更新多行时发生EOFException

时间:2018-02-16 03:33:21

标签: java sql-update relational-database hsqldb

多列,多行表...更新行/行的单元格/单元格... ..我逐行更新整个表格(可能不是一种有效的方式)...执行时我得到:

  java.sql.SQLTransientConnectionException: connection exception: 
  connection failure: java.io.EOFException

EOFException指的是我读到的数据流的结尾......它与我的代码有什么关系?

100行,10列,第1列是IDENTITY以1开头。

 for(int persistRowNum=1;persitRowNum<100;persistRowNum++){

try{
    resultSet.absolute(persistRowNum);

    if((newByteArrayOne.lenght)>0){
        resultSet.updateBytes(2,newByteArrayOne);
        resultSet.updateRow();
      }
      else{
        resultSet.updateBytes(2,resultSet.getBytes(2));
        resultSet.updateRow();
      }
   }catch(SQLException e){
       return;
   }

try{
   resultSet.absolute(persistRowNum);

    if((newByteArrayTwo.length)>0){
       resultSet.updateBytes(3,newByteArrayTwo);
       resultSet.updateRow();
    }
    else{
        resultSet.updateBytes(3,resultSet.getBytes(3));
        resultSet.updateRow();
    }
  }catch(SQLException e){
    return;
  }
}

这2张图片,首先显示我在第1行和第1行的4个单元格中输入的数据。 2。 执行后...第1行中输入的数据未显示,而第2行输入的数据仅为#3 ....更奇怪的是,第3行已经从执行后的表中消失了!

注意:persistRowNum是&#34; ID&#34;柱

enter image description here

enter image description here

最后是堆栈:

java.sql.SQLTransientConnectionException: connection exception: connection failure: java.io.EOFException
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCResultSet.performUpdate(Unknown Source)
at org.hsqldb.jdbc.JDBCResultSet.updateRow(Unknown Source)
at principal.PrincipalPageController.persistPrinStudTableChanges(PrincipalPageController.java:1077)
at principal.PrincipalPageController.access$2400(PrincipalPageController.java:47)
at principal.PrincipalPageController$34.handle(PrincipalPageController.java:1015)
at principal.PrincipalPageController$34.handle(PrincipalPageController.java:1011)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8863)
at javafx.controls/javafx.scene.control.Button.fire(Button.java:200)
at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3876)
at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3604)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1874)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2613)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:844)
 Caused by: org.hsqldb.HsqlException: connection exception: connection 
 failure: java.io.EOFException
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ClientConnection.execute(Unknown Source)
... 53 more

1 个答案:

答案 0 :(得分:0)

尽量避免在ResultSet的同一行上进行多次更新

for(int persistRowNum=1;persitRowNum<100;persistRowNum++){
try{
    resultSet.absolute(persistRowNum);

    if((newByteArrayOne.lenght)>0){
        resultSet.updateBytes(2,newByteArrayOne);
      } else{
        resultSet.updateBytes(2,resultSet.getBytes(2));
      }

    if((newByteArrayTwo.length)>0){
       resultSet.updateBytes(3,newByteArrayTwo);
    } else{
        resultSet.updateBytes(3,resultSet.getBytes(3));
    }

    resultSet.updateRow();

   }catch(SQLException e){
     return;
   }
}