一、类比JDBC的处理过程java
// 加载驱动 Class.forName("com.mysql.jdbc.Driver"); // 获取链接 String url \= "jdbc:mysql://127.0.0.1:3306/magic\_wen"; String user \= "root"; String password \= "root"; connection \= DriverManager.getConnection(url, user, password); // 获取statement, preparedStatement String sql \= "select \* from tb\_user where id='001'"; prepareStatement \= connection.prepareStatement(sql); // 设置参数 prepareStatement.setLong(1, 1l); // 执行查询 rs \= prepareStatement.executeQuery(); // 处理结果集
》容易碰见的问题记录:
一、加载驱动遇到SSL问题,提示WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决办法:jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false(禁用SSL)
二、空指针异常
解决办法:极可能是因为版本差别形成的,须要比较Mysql和mysql-connector-java-版本.jar,最好都保持在一个大版本级别上。
三、提示多个时区问题
解决办法:这是因为数据库和系统时区差别所形成的,在jdbc链接的url后面加上serverTimezone=GMT便可解决问题,若是须要使用gmt+8时区,须要写成GMT%2B8,不然会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。 加上这个 ?serverTimezone=UTC spring.datasource.url=jdbc:mysql://localhost:3306/exam?serverTimezone=UTCmysql
如下转载一篇文章,一篇搞明白myBatis:
https://blog.csdn.net/hellozp...spring