myBatis框架學習

一、類比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

相關文章
相關標籤/搜索