java.sql.SQLException: ORA-01002: 读取违反顺序 大家帮我看看

[code="java"]
public void insertImage(Image image)
{
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
OutputStream out = null;
try
{
conn = DBManager.getConnection();
stat = conn.createStatement();

    byte[] data = convertImage(image);

    String sql1 = "INSERT INTO PHOTO(ID,NAME,IMAGE) VALUES(1,'TEST',EMPTY_BLOB())";
    stat.execute(sql1);

    String sql2 = "SELECT IMAGE FROM PHOTO WHERE ID=1 FOR UPDATE";
    rs = stat.executeQuery(sql2);
    if(rs.next())
    {
        BLOB blob = (BLOB)rs.getBlob("IMAGE");
        out = blob.getBinaryOutputStream();
        try
        {
            out.write(data,0,data.length);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
}
catch(SQLException e)
{
    e.printStackTrace();
}
finally
{
    try
    {
        if(out != null)
            out.close();
        if(rs != null)
            rs.close();
        if(stat != null)
            stat.close();
        if(conn != null)
            conn.close();
    }
    catch(SQLException e)
    {
        e.printStackTrace();
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
}

}
[/code]
程序运行到
[code="java"]rs = stat.executeQuery(sql2);[/code]
就会抛出
[code="java"]
java.sql.SQLException: ORA-01002: 读取违反顺序

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:1198)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2400)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:572)
at com.computech.takepic.common.ImageDAO.insertImage(ImageDAO.java:39)
at com.computech.takepic.common.TestJMF$1.actionPerformed(TestJMF.java:104)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1766)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

[/code]

请大家帮我看下,谢谢。

dao

1个回答

也许访问数据库的模式是隐式提交的方式,即每一个SQL语句执行时,就自动的Commit,这样就发生这样的错误.改一下就可以了.
[code="java"]
conn.setAutoCommit(false);
[/code]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐