PreparedStatement setString失效求解
场景:实现条记录的更新,传入拼接过后的条件(No)
String sql = "UPDATE FB_J_FAULT_SHEET f SET f.DISTRIBUTION_STATUS = 1,f.DUTY_PERSON = ?"+
" WHERE f.SHEET_STREAM_NO in (?)";
Set<String> idSet = update_codition.keySet();
for(String key:idSet){
ps = conn.prepareStatement(sql);
ps.setString(1, key);
System.out.println(update_codition.get(key));
System.out.println(update_codition.get(key).substring(6,update_codition.get(key).length()-1));
ps.setString(2, update_codition.get(key).substring(6,update_codition.get(key).length()-1));//删除前6位 null,' 后一位'
System.out.println(ps.executeUpdate());
}
结果
null,'CTG1803140033111193'
CTG1803140033111193
1
null,'CTG17050800041171802','CTG17042600041171801'
CTG17050800041171802','CTG17042600041171801
0
操作依据,setString会自动给设置参数添加单引号。