Reputation: 5
Ok, I have been trying to connect to a database from a client program to a web server using java, and I will be very specific in this question.
I am using "ServersFree.com" as the web host that is hosting my database. I am using the latest java run time environment and the latest java SDK (JavaSE-1.7 as of the time of this writing). I am using windows 7 Home Premium as my platform for writing this program.
Here is what I am trying to do to attempt the connection to this web server and the database within:
try
{
String host = "jdbc:mysql://server17.serversfree.com/database";
String username = "admin";
String password = "example";
Connection con = DriverManager.getConnection(host, username, password);
}
catch(SQLException e)
{
System.out.println("There is an error with the SQL database: " + e.getMessage());
}
I have done some research for this and it turns out I might need a driver for the connection (seeing as I am getting an error from the output like this: "No suitable driver found for jdbc:mysql://server17.serversfree.com/database")
Output:
There is an error with the SQL database: No suitable driver found for jdbc:mysql://server17.serversfree.com/database
My questions are 1.) what driver is this program talking about that I don't have? and 2.) Where should I go or look to understand this problem?
Note: I noticed some people recommended not to use Microsoft's driver for this problem, and I tried looking for a jar file called "sqljdbc4.jar", but I had no luck finding it.
Any help would be appreciated. (anything that could point me to the right direction.)
Upvotes: 0
Views: 2470
Reputation: 1796
Please download the suitable driver from following link. You have to download the driver for operating system from which you are trying to connect.Inyour case this is windows.
the file would be just a JAR. file which you need to include in your classpath while executing the program.
Upvotes: 1
Reputation: 2774
You may need mysql-connector-java-{version}-bin.jar
in your classpath.
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://server17.serversfree.com/database", "admin",
"example");
catch(SQLException e)
{
System.out.println("There is an error with the SQL database: " + e.getMessage());
}
Upvotes: 0
Reputation: 52185
Most likely you need to download the official JDBC driver for MySQL (ConnectorJ).
SQLJDBC
seems to be for SQL databases, not MySQL.
Upvotes: 0