学习JDBC所遇到的一些问题归纳和总结

问题1:

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.
java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/web01

以上错误是因为,`com.mysql.jdbc.Driver'.已被弃用,在显示加载类的时候需要用`com.mysql.cj.jdbc.Driver'.来加载

问题2:

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.

问题原因:在设置url的时候没有规定字符,和时区问题

解决办法:String url ="jdbc:mysql://xxxxxxx6/xxxx?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";

 特别注意,时区问题一定要写成以上形式,即:serverTimezone=GMT%2B8;否则会报错

c3p0—config.xml 的jdbc-url的配置:jdbc:mysql://localhost:3306/bookstore?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true

问题3: 

Preparestatement 和 statement 一点小区别

 PrepareStatement pre = conn.prepareStatement(sql);
pre.excuteQuery();

Statement stmt = connStatement();

stmt.excuteQuery(sql);

问题4:

java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.

发布了32 篇原创文章 · 获赞 13 · 访问量 6900

猜你喜欢

转载自blog.csdn.net/weixin_43938351/article/details/102687635
今日推荐