2017-01-08 6 views
-1

バッチを使用してjtableの複数の行を更新することは可能ですか?それ以外の解決策がない場合は?私はここに挿入されていない更新ステートメントを意味します!事前に ありがとうバッチでjtableの複数の行を更新しますか?

try { 
    int rows = jTable1.getRowCount(); 
     cc.c.setAutoCommit(false); 

     String sql = "Insert into employyes(idemployyes,employyesName,employyesAge,employyesAddress) values (?,?,?,?)"; 
     cc.pst = cc.c.prepareStatement(sql); 
     for (int row = 0; row < rows; row++) { 
      String idemployyes = (String) jTable1.getValueAt(row, 0); 
      String employyesName = (String) jTable1.getValueAt(row, 1); 
      String employyesAge = (String) jTable1.getValueAt(row, 2); 
      String employyesAddress = (String) jTable1.getValueAt(row, 3); 

      cc.pst.setString(1, idemployyes); 
      cc.pst.setString(2, employyesName); 
      cc.pst.setString(3, employyesAge); 
      cc.pst.setString(4, employyesAddress); 

      cc.pst.addBatch(); 
      cc.pst.executeBatch(); 
      cc.c.commit(); 
     } 

    } catch (SQLException e) { 
     JOptionPane.showMessageDialog(this, e.getMessage()); 
    } 

答えて

-1

ここでは、答えは:

try { 
     int rows = jTable1.getRowCount(); 
     cc.c.setAutoCommit(false); 
     String sqlquery = "UPDATE employyes\n" 
       + "SET employyesName = ?,employyesAge = ?, employyesAddress = ?\n" 
       + "WHERE idemployyes = ?;"; 
     cc.pst = cc.c.prepareStatement(sqlquery); 
     for (int row = 0; row < rows; row++) { 
      String idemployyes = (String) jTable1.getValueAt(row, 0); 
      String employyesName = (String) jTable1.getValueAt(row, 1); 
      String employyesAge = (String) jTable1.getValueAt(row, 2); 
      String employyesAddress = (String) jTable1.getValueAt(row, 3); 


      cc.pst.setString(1, employyesName); 
      System.out.println(employyesName); 
      cc.pst.setString(2, employyesAge); 
      System.out.println(employyesAge); 
      cc.pst.setString(3, employyesAddress); 
      System.out.println(employyesAddress); 
      cc.pst.setString(4, idemployyes); 
      System.out.println(idemployyes); 

      cc.pst.addBatch(); 
      cc.pst.executeBatch(); 
      cc.c.commit(); 
     } 

    } catch (SQLException e) { 
     JOptionPane.showMessageDialog(this, e.getMessage()); 
    } 
関連する問題