以前使用JDBC时,都是导入相应的JDBC驱动jar包,然后加载驱动,再进行数据库连接。
1,写错驱动(针对最新版本的mysql)
<property name="DB.DRIVER" value="com.mysql.jdbc.Driver"/>
于是就报错
Loading class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver‘. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
意思是加载的这个类已经被弃用,新驱动类com.mysql.cj.jdbc.Driver,通过SPI自动注册,通常不需要手动加载。
//代码中不需要再使用Class.forName("com.mysql.jdbc.Driver"); //使用最新的驱动类 Class.forNmae("com.mysql.cj.jdbc.Driver");
2,没有指定时区
Error querying database. Cause: java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
这是由于数据库和系统时区差异所造成的,设置serverTimezone的值GMT/UTC即可。
3,url在xml文件用符号“&”代替“&”,在代码中则直接用“&”。
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '=true&useSSL=false&serverTimezone=GMT'.
4,SSL连接的设置问题,提示警告不建议使用没有带服务器身份验证的SSL连接
Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
在数据库连接的url中设置useSSL=false; 或者设置useSSL=true;并且提供服务器的验证证书。
完整设置url如下
<property name="DB.URL" value="jdbc:mysql://${DB.HOST}:${DB.PORT}/${DB.SID}?characterEncoding=utf8&useUnicode=true&useSSL=false&serverTimezone=GMT"/>
5,连接数据库时出现的Public Key Retrieval is not allowed错误提示
在连接数据库的url中,加上allowPublicKeyRetrieval=true参数。
posted on
浙公网安备 33010602011771号