Reputation: 11
We have the following code that runs in Linux Ubuntu, but not on Windows XP or Windows 7.
Do you know what could be the problem?
Here's the code snippet:
if (logger.isDebugEnabled())
{
logger.debug("before getting connection");
}
String url = "jdbc:mysql://XXX.XXX.XXX.XXX";
Connection conn = DriverManager.getConnection(url,"XXXX","XXXX");
if (logger.isDebugEnabled())
{
logger.debug("after getting connection");
}
Here are the logs, it can't find the driver.
0 [main] DEBUG main.Query1 - this is a sample log message.
0 [main] DEBUG main.Query1 - logger is enabled for sure
0 [main] DEBUG main.Query1 - before getting connection
16 [main] ERROR main.Query1 - Got an exception!
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at main.Query1.testQuery(Query1.java:41)
at main.Query1.main(Query1.java:21)
In our build path, we have:
Thanks.
Upvotes: 1
Views: 519
Reputation: 14505
Its possible that URL for DB connection you use is not correct. (Check db ip address and port)
Other reason could be you hadn't loaded the mysql driver, so the drivermanager don't know about the jdbc URL. Hope you have Class.forName("com.mysql.jdbc.Driver").newInstance();
in your code
Also you need to have mysql driver containing jar file (mysql-connector-java-5.1.13-bin.jar) in classpath of your running application.
Upvotes: 3