一、异常描述
通过DBUtilExt工具类对大文本字段oracle.sql.CLOB进行操作时报“java.sql.SQLException: ORA-01002: 提取违反顺序”错误异常,详细日志>>
java.sql.SQLException: ORA-01002: 提取违反顺序@b@@b@ at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)@b@ at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)@b@ at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)@b@ at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)@b@ at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:1198)@b@ at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2400)@b@ at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)@b@ at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:572)@b@ at com.xwood.java.util.DBUtilExt.updateCLOB(DBUtilExt.java:38)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.updateContext(PmsJavaContentFolderHandler.java:287)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.addOrUpdateContent(PmsJavaContentFolderHandler.java:419)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:237)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:274)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:274)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.parseJavainfo(PmsJavaContentFolderHandler.java:274)@b@ at com.xwood.java.luoku.pms.PmsJavaContentFolderHandler.handlerFile(PmsJavaContentFolderHandler.java:102)@b@ at com.xwood.java.luoku.pms.JavaFolderParseHandler.run(JavaFolderParseHandler.java:46)@b@ at com.xwood.java.persist.PmsJarAtomExecuteor.jobWBSEntry(PmsJarAtomExecuteor.java:22)@b@ at com.xwood.java.common.Root5sTimerMain$1.run(Root5sTimerMain.java:53)@b@ at java.util.TimerThread.mainLoop(Timer.java:555)@b@ at java.util.TimerThread.run(Timer.java:505)
二、解决方法
数据库的模式是隐式提交的方式,设置conn.setAutoCommit(false);即可解决问题。
原代码内容
public static int updateCLOB(String selectSql,String updateSql,int clobPostion,String clobValue){@b@ int retV=0;@b@ PreparedStatement ps = null;@b@ ResultSet rs = null;@b@ Statement st=null;@b@ try { @b@ ps = conn.prepareStatement(updateSql);@b@ ps.setClob(clobPostion, oracle.sql.CLOB.empty_lob()); @b@ retV=ps.executeUpdate(); @b@ st=conn.createStatement();@b@ rs = st.executeQuery(selectSql); @b@ if(rs.next()) { @b@ oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob(clobPostion); @b@ if(clob!=null){@b@ clob.putString(1,clobValue);@b@// clob.putChars(1, clobValue.toCharArray());@b@ }@b@ } @b@ conn.commit();@b@ st.close();@b@ }catch (Exception e) {@b@ try {@b@ conn.rollback();@b@ } catch (SQLException e1) {@b@ e1.printStackTrace();@b@ }@b@ retV=0;@b@ e.printStackTrace();@b@ }finally{@b@ try {@b@ if(ps!=null){@b@ ps.close();@b@ }@b@ DBUtil.close(null, ps, null);@b@ rs.close(); @b@ } catch (Exception ee) {@b@ } @b@ @b@ }@b@ return retV;@b@ }
改为
public static int updateCLOB(String selectSql,String updateSql,int clobPostion,String clobValue){@b@ int retV=0;@b@ PreparedStatement ps = null;@b@ ResultSet rs = null;@b@ Statement st=null;@b@ try {@b@ conn.setAutoCommit(false);@b@ ps = conn.prepareStatement(updateSql);@b@ ps.setClob(clobPostion, oracle.sql.CLOB.empty_lob()); @b@ retV=ps.executeUpdate(); @b@ st=conn.createStatement();@b@ rs = st.executeQuery(selectSql); @b@ if(rs.next()) { @b@ oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob(clobPostion); @b@ if(clob!=null){@b@ clob.putString(1,clobValue);@b@// clob.putChars(1, clobValue.toCharArray());@b@ }@b@ } @b@ conn.commit();@b@ st.close();@b@ }catch (Exception e) {@b@ try {@b@ conn.rollback();@b@ } catch (SQLException e1) {@b@ e1.printStackTrace();@b@ }@b@ retV=0;@b@ e.printStackTrace();@b@ }finally{@b@ try {@b@ if(ps!=null){@b@ ps.close();@b@ }@b@ DBUtil.close(null, ps, null);@b@ rs.close(); @b@ } catch (Exception ee) {@b@ } @b@ @b@ }@b@ return retV;@b@ }