0

I am trying to establish a connection to remote mysql db. I have put the jar connector towar/WEB-INF/lib folder and added a library (build path).

Still I am getting this error:

java.sql.SQLException: No suitable driver found for jdbc:sql4.freemysqlhosting.net
 at java.sql.DriverManager.getConnection(Unknown Source)

Here is the full code:

/**
 * 
 */
package com.infograph.dbconnection;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
/**
 * @author Vlad
 *
 */
public class DBConnection 
{
 /**
 * 
 */
 public DBConnection() 
 {
 try 
 {
 Class.forName("com.mysql.jdbc.Driver");
 } 
 catch (ClassNotFoundException e) 
 {
 System.out.println("Where is your MySQL JDBC Driver?");
 e.printStackTrace();
 return;
 }
 System.out.println("MySQL JDBC Driver Registered!");
 Connection connection = null;
 try 
 {
 connection = DriverManager.getConnection("jdbc:sql4.freemysqlhosting.net","user", "pass");
 } 
 catch (SQLException e1) 
 {
 System.out.println("Connection Failed! Check output console");
 e1.printStackTrace();
 return;
 }
 if (connection != null) 
 {
 System.out.println("You made it, take control your database now!");
 } 
 else 
 {
 System.out.println("Failed to make connection!");
 }
 }
}

What is the problem?? 10x!

asked Oct 8, 2013 at 20:19
2
  • What is sql4.freemysqlhosting.net? Commented Oct 8, 2013 at 20:20
  • it is the host of the db Commented Oct 8, 2013 at 20:22

2 Answers 2

1

I think what you meant to use is

connection = DriverManager.getConnection("jdbc:mysql://sql4.freemysqlhosting.net","user", "pass");

You possibly need to add a port number and schema name.

The URL you provided, jdbc:sql4.freemysqlhosting.net, is not valid, or at least it doesn't seem like it.

answered Oct 8, 2013 at 20:23
Sign up to request clarification or add additional context in comments.

Comments

1

Your connection url must be in form jdbc:mysql://hostname:port/schema in order for DriverManager to determine which driver to use. Here's more on this: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

answered Oct 8, 2013 at 20:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.