5

我以前多次使用 JDBC 没有任何问题,但由于某种原因,在我的新服务器上它无法正常工作。代码在我的主机上编译并运行良好,所有库(包括 JDBC)都应该编译成我运行的单个 JAR。

基本代码:

try
{
    Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
    System.err.println("Cannot load driver...");
    e.printStackTrace();
}

try
{
    connection = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=dbuser&password=dbpass");
    statement = connection.createStatement();
}
catch (SQLException e)
{
    System.err.println("Cannot connect to database...");
    e.printStackTrace();
}

错误:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.mysql.jdbc.Util.stackTraceToString(Util.java:355)
    at com.mysql.jdbc.Util.<clinit>(Util.java:120)
    at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:764)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:222)
    at com.test.Server.<init>(Server.java:78)
    at com.test.Server.main(Server.java:49)
Caused by: java.lang.RuntimeException: Can't load resource bundle due to underlying exception java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_GB
    at com.mysql.jdbc.Messages.<clinit>(Messages.java:61)
    ... 8 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_GB
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1539)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1278)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:733)
    at com.mysql.jdbc.Messages.<clinit>(Messages.java:59)
    ... 8 more

我以前从未遇到过这种错误,而且谷歌根本没有帮助。我已经检查了数据库凭据、端口号等。希望能提供任何帮助来解决它!

4

1 回答 1

-3

代替..

connection = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=dbuser&password=dbpass");

..bcoz 默认端口是 mysql 的 3306。如果更改,请给出

DriverManager.getConnection("jdbc:mysql://localhost:3306/minebench", "username", "password"); 

并添加“mysql-connector-java-5.1.0-bin.jar”。那就试试吧。

于 2014-04-11T12:19:09.547 回答