在最近做一些java web整合时,因为我在maven官网查找的资源,使用的最新版,6.0.3,发现Mysql连接中的几个问题,总结如下:
1、Loading class `com.mysql.jdbc.Driver'.This isdeprecated. The new driver class is `com.mysql.cj.jdbc.Driver。 按照书上的教程,写了如下的数据库连接配置:
2、如下提示: 警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1a0e2e48 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!七月 05, 2016 8:58:29 下午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run 警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1a0e2e48 -- APPARENT DEADLOCK!!! Complete Status: ... 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. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:695)
搜索了一下 需要在Url后面添加一个参数:
即完整的配置应修改为:
然后才能正常连接,加上后测试,连接成功。下图是测试代码以及测试结果:
3、Url中localhost:3306 可以省略,看到有的地方直接写的三个\\\,省略ip和端口,然后直接接某个数据库。因此测试了一下,将配置改为:
发现也是可以连上的。
4、使用Hibernate整合连接mysql时,出现以下错误: Disabling contextual LOB creation as createClob() method threw error :
java. lang. reflect. InvocationTargetException。 原因: at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:244) ,就是在配置的时候没取到值。那么为什么没取到值呢,是因为Hibernate默认是使用jdbc方式来取的,如果使用连接池的方式的话,必须告诉Hibernate一声,让它不使用单纯的JDBC连接。因此在Hibernate的hibernate.cfg.xml中加入一条属性:
但直接复制以上代码进去,也不会出错。。只能怀疑是eclipse补全功能的锅了!
|
|
来自: 昵称27831725 > 《Mysql数据库》