分享

JDBC连接时所犯错误1.字符集设置不合适2.连接MySQL8.0社区版时时区不一致3..包名不能以Java.命名4.驱动被弃用

 大前端之旅 2022-03-10

Microsoft JDBC Driver 的主页为:https://msdn.microsoft.com/en-us/data/aa937724.aspx
下载所需驱动
今天连接时报了四次错,记录下来
1.java.sql.SQLException: The server time zone value xxx异常解决方法
使用mybatis连接mysql8.0社区版时出现了这个异常信息,因为mysql默认的时区和本地时区不一致导致的
连接mysql时指定时区为UTC

jdbc:mysql://localhost:3306/db_book?serverTimezone=UTC

2.Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
处理:提示信息表明数据库驱动com.mysql.jdbc.Driver’已经被弃用了、应当使用新的驱动com.mysql.cj.jdbc.Driver
3.提示java错误:Exception in thread “main” java.lang.SecurityException: Prohibited package name: java.generic

问题所在:package java.book;定义包时不能以java.的形式定义
修改:package java1.book;结果运行正常
4.字符集不合适
解决办法:
private static final String URL="jdbc:mysql://localhost:3306/student后面加

?Unicode=true&characterEncoding=utf8

问题解决

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多