views:

52

answers:

2

Hi,

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:

  • mysql-connector-java-5.1.13-bin.jar
  • log4j-1.2.16.jar

Thanks.

+3  A: 

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.

YoK
Thanks, we were missing this: Class.forName("com.mysql.jdbc.Driver").newInstance();
anonymous
@anonymous You are welcome. You need to accept answer to improve your acceptance rate which motivates people to answer your question :).
YoK
+1  A: 

jdbc.drivers property configured correctly ?

Erwin Smout