简体   繁体   English

使用JDBC时是否出现MissingResourceException?

[英]MissingResourceException when using JDBC?

I've used JDBC without any problems many times before, but for some reason on a new server I have it isn't working. 我以前曾经多次使用JDBC没有任何问题,但出于某种原因,在新服务器上,我发现它不起作用。 The code compiles and runs fine on my main machine, and all the libraries (including the JDBC) should be compiled into a single JAR that I run. 代码在我的主机上编译并运行良好,所有库(包括JDBC)都应编译成我运行的单个JAR。

Basic code: 基本代码:

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();
}

The error: 错误:

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

I've never had this kind of error before, and Google is not being helpful at all. 我以前从来没有遇到过这种错误,谷歌根本没有帮助。 I've checked the database credentials, port number, etc. Would appreciate any help on solving it! 我已经检查了数据库凭据,端口号等。非常感谢您解决它的任何帮助!

Replace.. 更换..

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

with ..bcoz default port is 3306 for mysql.If changed give that 与..bcoz默认端口为3306 for mysql.If更改给予

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

and add "mysql-connector-java-5.1.0-bin.jar". 并添加“mysql-connector-java-5.1.0-bin.jar”。 then try it . 然后尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM