Java常见错误
java.lang.ClassNotFoundException
java.lang.ClassNotFoundException: “com.mysql.cj.jdbc.Driver” at java.net.URLClassLoader.findClass
1、看jar包是否可以被项目加载到
MySql
mysql 8.0驱动的jdbc连接
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL
jdbc.username=root
jdbc.password=root
驱动
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
1.hibernate.version=5.3.7.Final或以上
2.driverClass=“com.mysql.cj.jdbc.Driver”
3.jdbcUrl=jdbc:mysql://localhost:3306/maven?useSSL=false&serverTimezone=UTC
create_time timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’
则会出现以下的异常:
Invalid default value for ‘create_time’
原因:这个问题和mysql中sql_mode有关系,我们可以采用两种方法来查看它的值
SELECT @@sql_mode;
SHOW VARIABLES LIKE ‘sql_mode%’;
解决:
win下,修改my.ini:
sql_mode=‘STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
linux下,修改my.cnf[mysqld]:
sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
不重启:
set sql_mode=(select replace(@@sql_mode,‘NO_ZERO_IN_DATE,NO_ZERO_DATE’,’’));
上一篇: JSP EL表达式