關于search 查詢女神信息代碼 問題
else if(OPERATION_SEARCH.equals(in.toUpperCase())
||OPERATION_SEARCH.substring(0,1).equals(in.toUpperCase())
||OPERATION_SEARCH.equals(previous)){
previous =OPERATION_SEARCH;
//查找
List<Map<String,Object>> params=new ArrayList<Map<String,Object>> ();
Map<String,Object> param=new HashMap<String,Object>();
if(step==1){
System.out.println("請輸入的name:");
}else if(2==step){
param.put("name", in);
System.out.println("請輸入的關系:");
}else if(3==step){
param.put("rela", in);
System.out.println("請輸入的結果:");
}else if(4==step){
param.put("value", in);
params.add(param);
try {
List<Goddess> gs =action.query(params);
for(Goddess g:gs){
System.out.print(g.toString());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(OPERATION_SEARCH.equals(previous)){
step++;
}
}
最后顯示結果
select * from imooc_goddess where 1=1 and null null 3
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null 3' at line 1
不知道最后sql為什么是null,不是傳了值嗎
2016-12-10
-Allen說的方法是對的,親測可用
2016-09-20
我也出現了同樣的問題,因為要添加字符串,但是就不能接受自己輸入的值了
2016-08-06
造成前面兩個null的原因是下面這兩行要放在while循環外面,
List<Map<String,Object>> params=new ArrayList<Map<String,Object>> ();
Map<String,Object> param=new HashMap<String,Object>();
2016-08-06
param.put("name", "'"+in+"'");//加上一對單引號試試