日期:2014-05-17  浏览次数:20748 次

批处理出错 语句拿到数据库里可以执行 操作一条记录可以多了就会报错 报命令未正确结束 在线等啊!!!!!
java.sql.BatchUpdateException: 批处理中出现错误: ORA-00933: SQL 命令未正确结束 
DELETE i_define WHERE CodeId = 'micro_query' AND userid = '0' and id = '13208' 

上面是报错信息
我删除一条记录可以,但是一旦大于1条就开始报上面的错
sql = " DELETE i_define WHERE CodeId = '" + CodeId + "' AND userid = '" + userid + "'"; 
System.out.println( tmp_chk+"--tmpchk--" + tmp_chk2);
if( !tmp_chk.equals("")){
String[] array_z = tmp_chk.split(",");
for(int i_z1 = 0; i_z1<array_z.length;i_z1++){
sql2 = sql + " and id = " + array_z[i_z1];
System.out.println(sql2+ "--sql6-"+i_z1);
stmt_batch.addBatch(sql2);//就是说这里错 我删除一条记录可以,但是一旦大于1条就开始报上面的错
}
/*这段不行我才用上面的for循环,我想的就是一起不行看看分开一条一条的行不行,可惜还是不行..
  sql2 = sql + " AND id IN (" + tmp_chk + ");";
System.out.println(sql2+ "--sql6");
sql2 = sql2.replace(",","||");

stmt_batch.addBatch(sql2);*/
//stmt_z.executeUpdate(sql2);
}
......省略代码
try{
stmt_batch.executeBatch();//
operate_tag = 1;
}
catch(Exception e){
out.print(e+"<p>" + sql2);
operate_tag = -1;
}

stmt_batch.close();

下面是对应的控制台输出

DELETE I_MICRO_QUERY_ITEM WHERE userid='0' AND id IN('13207','13208')--sql2
DELETE I_MICRO_QUERY WHERE userid='0' AND id IN('13207','13208')--sql2
DELETE i_define_privi WHERE CodeId='micro_query' AND userid='0' AND id IN('13207','13208')--sql4
'13207','13208'--tmpchk--
 DELETE i_define WHERE CodeId = 'micro_query' AND userid = '0' and id = '13207'--sql6-0
 DELETE i_define WHERE CodeId = 'micro_query' AND userid = '0' and id = '13208'--sql6-1

------解决方案--------------------
方便的话,我给你调试下,看看什么情况,1309000237
------解决方案--------------------
不要批量执行sql了,一句一句执行吧,addBatch这个方法的源码也看不到,不清楚最后它是怎么拆了执行的。