Perhatikan source code dibawah ini. Saya akan menginput ke tabel buku data yang ada pada JList.
dataBase d = new dataBase();
Connection con = null;
PreparedStatement psmt = null;
ResultSet rs = null;
DefaultListModel list1 = new DefaultListModel();
DefaultListModel list2 = new DefaultListModel();
try {
con = d.getCon();
for (int i = 0; i < jList1.getModel().getSize(); i++) {
String item1 = jList1.getModel().getElementAt(i).toString();
String item2 = jList2.getModel().getElementAt(i).toString();
String SQL3 = "INSERT INTO buku VALUES(?,?)";
psmt = con.prepareStatement(SQL3);
psmt.setString(1, item1);
psmt.setString(2, item2);
psmt.executeUpdate();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
Connection con = null;
PreparedStatement psmt = null;
ResultSet rs = null;
DefaultListModel list1 = new DefaultListModel();
DefaultListModel list2 = new DefaultListModel();
try {
con = d.getCon();
for (int i = 0; i < jList1.getModel().getSize(); i++) {
String item1 = jList1.getModel().getElementAt(i).toString();
String item2 = jList2.getModel().getElementAt(i).toString();
String SQL3 = "INSERT INTO buku VALUES(?,?)";
psmt = con.prepareStatement(SQL3);
psmt.setString(1, item1);
psmt.setString(2, item2);
psmt.executeUpdate();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
Related Posts
thanks a lots , i was looking for long times for this code.. i am thankful for you man
BalasHapusYou are welcome bro.
HapusCheck also my youtube video.:)
https://www.youtube.com/watch?v=BoN0SmQnQps
video nya udah gak ada
Hapus