Mike W
Mike W

Reputation: 1148

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. In production, the MySQL connection uses SSL, but it doesn't use SSL in development mode. 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.

Now, I am adding a database connection pool using C3P0. Instead of getting a connection from DriverManager.getConnection, I get the connection from C3P0 by calling POOL.getConnection().

The code that sets up C3P0 is pretty simple:

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. I've removed "&useSSL=false" from the DB_URL, and everything works ok, except that now I'm getting the MySQL SSL warnings.

Can anyone advise me on how to correctly configure C3P0 so that I no longer get the MySQL SSL warnings?

Upvotes: 0

Views: 1106

Answers (1)

Steve Waldman
Steve Waldman

Reputation: 14083

JDBC Connections silently collect warnings that must be actively checked to be seen. Most applications never check them. c3p0 does. Whenever a Connection is checked back in, c3p0 checks, logs, and clears Connection warnings before making the Connection available again within the pool.

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. 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.

See SQLWarnings.

Upvotes: 1

Related Questions