2017-01-08 5 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()); 
    } 
Смежные вопросы