mysql-connector-java.jar包版本引入的是8.0.11版本的,
就是版本问题,
有两种解决方法:
1.退回到5.x版本,其他配置不变
2.修改jdbc.properties文件
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true");
public class JDBCTest {
@Test
public void fun() throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true");
dataSource.setUser("root");
dataSource.setPassword("11120750ZYY");
JdbcTemplate jt = new JdbcTemplate();
jt.setDataSource(dataSource);
String sql="insert into t_user values(null,'zyy') ";
jt.update(sql);
}
}