sql中带有like时如何使用预编译。

Java代码如下:

String str = "长江";Connection conn = null; PreparedStatement ps = null; //比较preparestatement和statement ResultSet rs = null; try { //2.建立连接 conn = JdbcUtils.getConnection(); //3.创建语句 String stl = "SELECT * FROM jeesci WHERE title like ?"; ps = conn.prepareStatement(stl); ps.setString(1, "%"+str+"%"); //将第一个问号替换成na //4.执行语句 rs = ps.executeQuery();

你可能感兴趣的:(sql,like)