JDBC c3p0 配置异常:java.sql.SQLException: Connections could not be acquired from the underlying database

一、问题描述
在c3p0配置过程中,遇到如下异常:
java.sql.SQLException: Connections could not be acquired from the underlying database

此异常为c3p0配置异常,c3p0.xml文件配置没有配置对!

初始配置如下:


		root
		123
		com.mysql.jdbc.Driver
		jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

用此配置文件运行后会弹出:
在这里插入图片描述
且c3p0数据池不能成功连接。

二、如何解决
c3p0.xml 文件中对于 ‘&’ 需要转义成 ‘&;’!!
即在 & 后需要加上 amp;
代码如下:


		root
		123
		com.mysql.jdbc.Driver
		jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

再运行,c3p0 连接成功!为了验证成功连接,增加打印语句

System.out.println(connection);

成功连接!
JDBC c3p0 配置异常:java.sql.SQLException: Connections could not be acquired from the underlying database_第1张图片

你可能感兴趣的:(异常处理)