对一个学生表进行模糊查询名字,占位符要怎么写才对,试过多次,不是报错就是返回的查询记录结果是0。。。各位大佬们,模糊查询时如果要使用占位符时要怎么做?
//根据性别和姓名的模糊查询查找学生
String sql = "select * from student where name like '%?%' and sex = 0;";
PreparedStatement ps = connection.prepareStatement(sql);
//ps.setString(1,"精");
ResultSet rs = ps.executeQuery();
System.out.println(rs.next());
while(rs.next()){
System.out.println("id:"+rs.getInt("id")+
"name:"+rs.getString("name")+
"sex:"+rs.getBoolean("sex")+
"birthday:"+rs.getDate("birthday"));
}