关于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