
java.sql.SQLException: Can not issue data manipulation statements with executeQuery ().|
报错: java.sql.SQLException: Can not issue data manipulation statements with executeQuery ().|在使用JDBC进行like语句的时候,使用的是PreparedStatement接口,所以就要设置?
·
在使用JDBC进行like语句的时候,使用的是PreparedStatement接口,所以就要设置?的值
在进行传递赋值的时候,需要注意的是要直接将值传递给方法,需要将值拼接为"%"+值+"%"的形式
如果没有将参数拼接起来,就像下面一样
// 例如这里有一个实现类B,实现一个接口B
public class B extends BaseDao implements A{
//实现接口中的进行模糊查询的方法
public int getUserCountByName(String name){
String sql = "select count(*) from user where uName like ?";
Object[] params[] = {name};
rs = super.query(sql,params);
.....
return ...
}
}
报错: java.sql.SQLException: Can not issue data manipulation statements with executeQuery ().|
要将?值拼接两个%号
// 例如这里有一个实现类B,实现一个接口B
public class B extends BaseDao implements A{
//实现接口中的进行模糊查询的方法
public int getUserCountByName(String name){
String sql = "select count(*) from user where uName like ?";
Object[] params[] = {"%"+name+"%"};
rs = super.query(sql,params);
.....
return ...
}
}
感谢观看!~~~
更多推荐
所有评论(0)