数据库模糊查询
那位高手看一下,为什么以下代码只要加上传过来的参数就无法进行模糊查询呀,每次都是空的.但是我把问号手动的变为 '罗%'这种形式,它又能查询,什么原因呀,急求,谢谢.public List queryLike(String con) throws Exception
{
String sql="select * from Student where name like ?";
conDao cd=new conDao();
List li=new ArrayList();
ResultSet rs=null;
PreparedStatement pst=null;
try{
pst=cd.getCon().prepareStatement(sql);
pst.setString(1,"%"+con+"%");
rs=pst.executeQuery();
while(rs.next())
{
Student stu=new Student();
stu.setId(rs.getString(1));
stu.setName(rs.getString(2));
stu.setAge(rs.getInt(3));
li.add(stu);
}
rs.close();
pst.close();
}catch(Exception e)
{
System.out.println("操作异常");
}finally
{
cd.close();
}
return li;
}