關於Mysql查詢帶單引號及插入帶單引號字符串問題


1.轉為帶參數查詢
String sql=""select id from student where name='?';
Connection connect = DriverManager.getConnection( "jdbc:mysql://10.82.80.7:3306/haitao" , "root" , "123456" );
PreparedStatement pStmt = connect .prepareStatement( sql );
pStmt .setString(1, name );
pStmt .executeUpdate();
2.將字符串中的單引號轉換為兩個單引號。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM