2016-03-19 9 views
0

. Benim sorunum, tüm diğer satırlar güncellendiğinde tek bir satırın aynı değerleri almasıdır. Sadece bir satır güncellenmiş ve diğer tüm çoğaltılmış demek istiyorum. iyi bir yaklaşımla yardım edebilir. teşekkürlerjtable hücre değerlerini nasıl düzenleyeceğimi/güncelleyeceğimi jpeg hücrelerini aşağıdaki kodumdaki gibi düzenlemeye ve güncellemeye çalışıyorum

int count = Table_purchase.getRowCount(); 
    int col = Table_purchase.getColumnCount(); 
    String pod_id[] = new String[count]; 
    String po_id[] = new String[count]; 
    String order_qty[] = new String[count]; 
    String item_id[] = new String[count]; 
    String unit_price[] = new String[count]; 
    String recived_qty[] = new String[count]; 
    String rejected_qty[] = new String[count]; 

    for (int i = 0; i < count; i++) { 
     po_id[i] = Table_purchase.getValueAt(i,0).toString(); 
     pod_id[i] = Table_purchase.getValueAt(i,1).toString(); 
     order_qty[i] = Table_purchase.getValueAt(i,2).toString(); 
     item_id[i] = Table_purchase.getValueAt(i,3).toString(); 
     unit_price[i] = Table_purchase.getValueAt(i,4).toString(); 
     recived_qty[i] = Table_purchase.getValueAt(i, 5).toString(); 
     rejected_qty[i] = Table_purchase.getValueAt(i,6).toString(); 

     try { 
      String sql = "update purchase.purchase_detail set pod_id='" + pod_id[i] + "',order_qty='" + order_qty[i] + "',item_id='" + item_id[i] + "', unit_price='" + unit_price[i] + "', recived_qty='" + recived_qty[i] + "',rejected_qty='" + rejected_qty[i] + "'where po_id= '" + po_id[i] + "'"; 
      pst = conn.prepareStatement(sql); 
      pst.execute(); 
      JOptionPane.showMessageDialog(null, "updated"); 
     } catch (Exception e) { 
      JOptionPane.showMessageDialog(null, e); 
     } 

    } 

cevap

0

bir yerde-maddesini, dolayısıyla veri tabanı tablosundaki tüm satırlar salıncak masa-satırların her okunması için güncellenmiş ve sonunda edilir içermiyor Kişisel sql deyimi, tüm veritabanı-satırlar olacak son swing-table-row değerlerini al.

(Ve, pst.setParameter (http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) kullanın ve sql'yi gui koduna karıştırmayın.)

İlgili konular