Oracle占位符?的模糊查询

在模糊查询语句中,需要用到占位符“?”传递参数时,sql语句中不能有%,如下:

正确写法

PreparedStatement ps = null;
ResultSet rs = null;
Connection conn = null;
String sql = "select * from users where name like ?";
ps = conn.prepareStatement(sql);
ps.setString(1, "%"+name+"%");
rs = ps.executeQuery();

猜你喜欢

转载自blog.csdn.net/qq_36135335/article/details/82702986
今日推荐