开发者

Database connection code runs on Linux but not Windows

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技巧 
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.


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.


jdbc.drivers property configured correctly ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜