title: Using bytes to save object data from table to database in java
body: <p>After some research it seems that I should be modifying my Object into bytes before sending. As my code is rather extensive i will give it in demonstrative pieces. I have the problem that nothing happens on successful completion of the program.</p>
  
  <p>SAVE and SET variables are named in the following manner within the private void</p>
  
  <pre><code>int count = jTable1.getRowCount();
  
      for(int i=0;i&lt;count;i++){
  //SET0       
          SET0 = new Object[1][count];
          SET0[0][i] = txt.getText();
          ByteArrayOutputStream baosSET0 = new ByteArrayOutputStream();
          ObjectOutputStream oosSET0 = new ObjectOutputStream(baosSET0);
          oosSET0.writeObject(SET0.toString());
          byte[] SET0asBytes = baosSET0.toByteArray();
          ByteArrayInputStream baisSET0 = new ByteArrayInputStream(SET0asBytes);
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>      SAVE = new Object[1][count];  
        SAVE[0][i] = jTable1.getModel().getValueAt(i,0);
        ByteArrayOutputStream baosSAVE = new ByteArrayOutputStream();
          ObjectOutputStream oosSAVE = new ObjectOutputStream(baosSAVE);
          oosSAVE.writeObject(SAVE.toString());
          byte[] SAVEasBytes = baosSAVE.toByteArray();
          ByteArrayInputStream baisSAVE = new ByteArrayInputStream(SAVEasBytes);
  </code></pre>
  
  <p>Which leads into my SQL query:</p>
  
  <pre><code> String sqla1 = "INSERT INTO MIT(MTY_KOD,MTY_TYY,MTY_ALU,MTY_PAR1,MTY_PAR2,MTY_TOL,MTY_KAN,MTY_DATE) values(?,?,?,?,?,?,?,?);";
  
   try{
         pst = conn.prepareStatement(sqla1);
  
     pst.setBinaryStream(1, baisSET0 , SET0asBytes.length);
     pst.setBinaryStream(2, baisSET2, SET2asBytes.length);
     pst.setBinaryStream(3, baisSET1, SET1asBytes.length);
     pst.setBinaryStream(4, baisSAVE, SAVEasBytes.length);
     pst.setBinaryStream(5, baisSAVE3, SAVE3asBytes.length);
     pst.setBinaryStream(6, baisSAVE5, SAVE5asBytes.length);
     pst.setBinaryStream(7, baisSET3, SET3asBytes.length);
     pst.setBinaryStream(8, baisSET2, SET2asBytes.length);
  
     pst.executeUpdate();}
   catch (Exception e) {
     System.out.println(e);
          }
  </code></pre>
  
  <p>Event is triggered from:</p>
  
  <pre><code>if(txt.getText().isEmpty()){
      }else{ 
          try{
      INSERT();}
          catch(IOException ex){
          System.out.println(ex);
          }
      }
  </code></pre>
  
  <p>The error i get is:</p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: The stream value is not the specified length. The specified length was 35, the actual length is 0.
  </code></pre>
  
  <p>Can anyone direct me on how to fix this error... or a different method of saving the information? Thank you.</p>