java中使用where in()修改使用checkbox提交选中记录的同一字段时报如下错误:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '8,10,11'
其中8,10,11为提交的数据拼接的字符串
action中接受checkbox提交数据的代码:
public ActionForward submitApply(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException {
String[] ids = request.getParameterValues("ids");
String str = "";
for (int i = 0; i < ids.length; i++) {
str += ids[i];
if(i<ids.length-1){
str += ',';
}
}
System.out.println(str);
RefundDao.submitApply(request.getParameter("uid"), str);
return mapping.findForward("applylist");
}
Dao中执行sql代码如下:
public static void submitApply(String uid,String str) throws SQLException {
BaseConnection con = new BaseConnection();
Connection conn = con.getConnection();
String sql ="UPDATE refund SET state=1 where id in(?);";
PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(sql);
stmt.setString(1, str);
stmt.executeUpdate();
}
在mysql 客户端中直接执行:
UPDATE refund SET state=1 where id in(8,10,11);没有错误。
请各位大侠指点
------解决方案--------------------
从前台传入到后台一个字符串。
sql语句可以改为:
public static void submitApply(String uid,String str) throws SQLException {
BaseConnection con = new BaseConnection();
Connection conn = con.getConnection();
String sql ="UPDATE refund SET state=1 where id in("+str+");";
PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(sql);
stmt.executeUpdate();
}
------解决方案--------------------
已经解决了,谢谢