应用程序运行一段时间后出现 JDBC 错误
MySQL Connector/J(版本 5.1.6)在每秒打开和关闭连接几分钟后出现以下错误:
java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/someQueue
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
...
代码很简单:
Connection connection = DriverManager.getConnection(this.url, this.connectionProperties);
其中 this.url
是在stacktrace,并且 this.connectionProperties 是:
Properties props = new Properties();
props.put("user", "root");
props.put("password", "root");
我尝试用旧方法修复它,并在 DriverManager.getConnection(...)
之前添加以下内容:
Class.forName("com.mysql.jdbc.Driver");
但是它没有帮助。有人吗?
谢谢您的宝贵时间!
MySQL Connector/J (version 5.1.6) gets me the following error after a few minutes of opening and closing connections every second):
java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/someQueue
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
...
The code is simply:
Connection connection = DriverManager.getConnection(this.url, this.connectionProperties);
Where this.url
is the URL found in the stacktrace, and this.connectionProperties
is:
Properties props = new Properties();
props.put("user", "root");
props.put("password", "root");
I tried fixing it doing it the old way, and adding the following right before the DriverManager.getConnection(...)
:
Class.forName("com.mysql.jdbc.Driver");
But it didn't help. Anyone?
Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点偏离主题,但是有什么原因不能使用连接池吗?这将为您节省每次创建新连接的开销。查看 Commons-DBCP 以获得可用的库(文档中有示例)。
This is slightly off-topic, but is there a reason you can't use a connection pool? This will save you the overhead of creating a new connection each time. Check out Commons-DBCP for a library which will work (there are examples in the documentation).
JRuby 版本 1.6.0_RC2 是问题所在。
尽管它没有在 JDBC 代码中积极使用,但我在启动应用程序时加载了一个脚本。
影响 JDBC 驱动程序的错误可以在这里找到:JRUBY-5528
谢谢大家的帮助。
JRuby version 1.6.0_RC2 was the problem.
Even though it wasn't actively used in the JDBC code, I'm loading a script when I launch my app.
The bug affecting the JDBC drivers can be found here: JRUBY-5528
Thank you all for your help.