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