简体   繁体   English

使用Java,JDBC和C3P0时摆脱MySQL SSL警告

[英]getting rid of MySQL SSL warning when using Java, JDBC and C3P0

I have a simple JDBC app (not using Spring or Hibernate) that connects to MySQL. 我有一个连接到MySQL的简单JDBC应用程序(不使用Spring或Hibernate)。 In production, the MySQL connection uses SSL, but it doesn't use SSL in development mode. 在生产中,MySQL连接使用SSL,但在开发模式下不使用SSL。 In development mode, I added "&useSSL=false" to the database URL in order to prevent the MySQL warning "Establishing SSL connection without server's identity verification is not recommended" from filling up my log files. 在开发模式下,我在数据库URL中添加了"&useSSL=false" ,以防止MySQL警告“建议不要在没有服务器身份验证的情况下建立SSL连接”来填充我的日志文件。

Now, I am adding a database connection pool using C3P0. 现在,我正在使用C3P0添加数据库连接池。 Instead of getting a connection from DriverManager.getConnection , I get the connection from C3P0 by calling POOL.getConnection() . 我不是通过DriverManager.getConnection获得连接,而是通过调用POOL.getConnection()从C3P0获得连接。

The code that sets up C3P0 is pretty simple: 设置C3P0的代码非常简单:

POOL = new ComboPooledDataSource();
POOL.setDriverClass("com.mysql.cj.jdbc.Driver");
POOL.setJdbcUrl(DB_URL);
POOL.setUser(USER);
POOL.setPassword(PASSWORD);

The problem is that this doesn't work. 问题是这行不通。 If the DB_URL string contains "&useSSL=false" , then POOL.getConnection() hangs. 如果DB_URL字符串包含"&useSSL=false" ,则POOL.getConnection()挂起。 I've removed "&useSSL=false" from the DB_URL , and everything works ok, except that now I'm getting the MySQL SSL warnings. 我已经从DB_URL删除了"&useSSL=false" ,并且一切正常,除了现在我收到了MySQL SSL警告。

Can anyone advise me on how to correctly configure C3P0 so that I no longer get the MySQL SSL warnings? 谁能为我提供有关如何正确配置C3P0的建议,以使我不再收到MySQL SSL警告?

JDBC Connections silently collect warnings that must be actively checked to be seen. JDBC连接以静默方式收集警告,必须对其进行主动检查以使其可见。 Most applications never check them. 大多数应用程序从不检查它们。 c3p0 does. c3p0做到了。 Whenever a Connection is checked back in, c3p0 checks, logs, and clears Connection warnings before making the Connection available again within the pool. 只要重新签入Connection,c3p0就会检查,记录并清除Connection警告,然后再使Connection在池中可用。

If the logging of warnings is annoying to you, just configure your logging library to filter them. 如果警告日志使您烦恼,只需配置您的日志库以过滤警告。 All warnings are logged at INFO to a logger called com.mchange.v2.c3p0.SQLWarnings . 所有警告都在INFO处记录到名为com.mchange.v2.c3p0.SQLWarnings的记录器中。 Just configure whatever logging library you are using not to log `com.mchange.v2.c3p0.SQLWarnings, or to filter it to a higher level of severity than INFO. 只需配置您正在使用的任何日志记录库即可不记录`com.mchange.v2.c3p0.SQLWarnings或将其过滤到比INFO更高的严重性级别。

See SQLWarnings . 请参阅SQLWarnings

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

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