Advertisement
Guest User

Untitled

a guest
Nov 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. JButton btnDeleteCourse = new JButton("Delete Course");
  2. btnDeleteCourse.addActionListener(new ActionListener() {
  3. public void actionPerformed(ActionEvent e) {
  4. int row = tableCourse.getSelectedRow();
  5. DefaultTableModel model= (DefaultTableModel)tableCourse.getModel();
  6.  
  7. String selected = model.getValueAt(row, 0).toString();
  8.  
  9. if (row >= 0) {
  10.  
  11. model.removeRow(row);
  12.  
  13. try {
  14. Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://eu-cdbr-azure-west-b.cloudapp.net:3306/harmaala_ella", "b13c4327297c36", "6591036a");
  15. PreparedStatement ps = (PreparedStatement) conn.prepareStatement("delete from courses where courseName='"+selected+"' ");
  16. ps.executeUpdate();
  17. }
  18. catch (Exception w) {
  19. JOptionPane.showInputDialog(this, "Connection Error!");
  20. }
  21. }
  22.  
  23. }
  24. } );
  25. btnDeleteCourse.setBounds(42, 274, 117, 29);
  26. getContentPane().add(btnDeleteCourse);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement