java.sql.SQLException: 批处理中出现错误: batch must be either executed or cleared
2014-05-15 14:46
931 查看
问题:
} else { sb.append(" and E.DATA_TYPE IS NULL "); } //检验数据库中是否有重复数据 re=queryState.executeQuery(sb.toString()); if (re != null && re.next()) { String ID=re.getString("event_id"); //注意:DATAVALUE不为空时才修改数据.否则不修改 if(DATAVALUE!=null&&!"".equals(DATAVALUE)){ String sql="update "+toTable+" set PARAM_VALUE='"+DATAVALUE+"',LAST_MODIFIED=to_date(to_char(sysdate,'yyyy-MM-dd'),'yyyy-MM-dd') where EVENT_ID='"+ID+"'"; invokeState.addBatch(sql);//执行SQL 语句,插入、更新、删除数据 } } else { //DATAVALUE不为空时才插入数据.否则不插入 if(DATAVALUE!=null&&!"".equals(DATAVALUE)){ String sql="insert into "+toTable+" " + "(TABLE_ID,PARAM_ID,PARAM_VALUE,KOUJING,FREQUENCE,AREA_CODE,DATA_SOURCE,THRESHOLD,PARAM_UNIT,EDITION_ID,INPUT_DATATIME,LAST_MODIFIED,DATA_TYPE,ORDERS,REMARK) " + "values(\'"+TABLE_ID+"\',\'"+DATAID+"\',\'"+DATAVALUE+"\',\'"+KOUJING+"\',\'"+FREQUENCE+"\',\'"+REGION+"\',\'"+SOURCE+"\',\'"+THRESHOLD+"\',\'"+UNIT+"\'," + "\'"+EDITION+"\',to_date(\'"+UPLOADTIME+"\','yyyy-MM-dd\'),\'\',\'"+DATATYPE+"\',\'"+ORDERS+"\',\'"+REMARK+"\')"; invokeState.addBatch(sql);//执行SQL 语句,插入、更新、删除数据 } } } } invokeState.executeBatch();//批处理,多条SQL 语句可以一次性执行完毕,称为批处理操作 long endTime= System.currentTimeMillis(); logger.info("start time:"+endTime); logger.info("total time:"+(endTime-startTime)); 运行到 invokeState.addBatch(sql);就报错了,我去数据库执行了SQL结果为空没有符合的数据,是这个原因么有点不确定 2012-10-10 14:14:46,900 ERROR [FileUploadInterceptor.java:228] : Could not find a Content-Type for file. Verify that a valid file was submitted. java.sql.SQLException: 批处理中出现错误: batch must be either executed or cleared at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
解决方法:一般通过另一个Statement操作就行了,即查询和插入,修改,不能共用一个stateMent; 但有时使用批处理也有一定的局限性,比如在成批导入数据时,如果不考虑唯一性,当然比较方便,但如果考虑这个问题就有点麻烦了,因为批处理一定要executeBatch()后才生效, 但在这个过程中,就无法判断临时表是否已经插入了同样的一条记录; 检查一下commit部分的语句发现,如有pstmt.executeBatch();改成了pstmt.executeUpdate();
相关文章推荐
- java.sql.SQLException: 批处理中出现错误: batch must be either executed or cleared
- java.sql.SQLException: The SQL statement must not be null or empty.这个错误
- 出现错误 Element type "LinearLayout" must be followed by either attribute specification,">"or"/>"的解决办法
- 打开eclipse出现错误A java Runtime Environment(JRE) or Java Development Kit(JDK) must be...
- 使用mysql-connector-java.jar连接MySql时出现:Error while retrieving metadata for procedure columns: java.sql.SQLException: Parameter/Column name pattern can not be NULL or empty.
- jstl学习常见错误一: The absolute uri: http://java.sun.com/jst/core cannot be resolved in either web.xml or the jar files deployed with
- java使用Sqlite 出现类似java.sql.SQLException: no such table: employee错误
- java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误
- Xcode编译错误:Synthesized property 'xxxXXX' must either be named the same as a compatible ivar or mus
- java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误
- java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this way, or a Connection
- ubuntu 打开eclipse出现A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be ... 解决方法
- 经典错误重现->Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to
- svm 出现 Y must be a vector or a character array的错误
- Eclipse启动错误:A Java Runtime Environment(JRE) or Java Development Kit(JDK) must be available……
- MySql系列:中文写入数据库出现错误java.sql.SQLException: Incorrect string value: '\xE5\xxxx' for column 'xxxx' at row 1及其解决方法
- Hibernate插件出现错误 java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver
- Android开发出现Java.lang.IllegalStateException的原因;Target host must be null,or set in parameters
- java.sql.SQLException: ORA-00917: 缺少逗(log4j在数据库中插入相应信息时出现了此错误)
- ssm、ssh 出现 java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.T