problems in removing recodrds from database of jList

Yeah

New Member
Hello I have the problem.. can anyone give me snippet? i have the table of MySql that display JList item so I can add the item easily but can't remove it from database? while pressing remove item?I searched a lot no one has ever need of doing.. i wonder how its possible?\[code\]private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","ubuntu123"); PreparedStatement stmt = null; ResultSet rs = null; String [] data; data = http://stackoverflow.com/questions/15742286/new String[100]; int i=0; DefaultListModel listmodel = (DefaultListModel) jList2.getModel(); int selectedIndex = jList2.getSelectedIndex(); if (selectedIndex != -1) { listmodel.remove(selectedIndex); String query ="delete from supplierinfo where companyname = ?"; stmt = (PreparedStatement) con.prepareStatement(query); stmt.setInt(1, i); stmt.execute(); con.close(); // i= i+1; } } catch(Exception e) { System.out.println("3rd catch " +e); }} \[/code\]
 
Back
Top