Guest User

Untitled

a guest
Nov 25th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. private void billdeleteActionPerformed(java.awt.event.ActionEvent evt) {
  2. // TODO add your handling code here:
  3. try{
  4. Class.forName("oracle.jdbc.driver.OracleDriver");
  5. int id=Integer.parseInt(billidtext.getText());
  6. try (//step2 create the connection object
  7. Connection con = DriverManager.getConnection("jdbc:oracle:thin:localhost:xe","hr","****")) {
  8. Statement stmt=con.createStatement();
  9. stmt = con.createStatement();
  10. String sql = "DELETE FROM bill " +
  11. "WHERE bid = ('"+id+"')";
  12. int w=stmt.executeUpdate(sql);
  13. if(w!=0)
  14. JOptionPane.showMessageDialog(null,"Deleted Successfully!"); //this is displayed successfully
  15. else
  16. JOptionPane.showMessageDialog(null,"value does not exists!");// this is displayed successfully
  17. supplieridtext.setText("");
  18.  
  19. //view trigger
  20. String sql1="SELECT * FROM bill";
  21.  
  22. stmt = con.createStatement();
  23.  
  24. ResultSet rs = stmt.executeQuery(sql1);
  25. //STEP 5: Extract data from result set
  26. billtable.setModel(DbUtils.resultSetToTableModel(rs));
  27. rs.close();
  28.  
  29. //step5 close the connection object
  30. }
  31. }catch( ClassNotFoundException | SQLException e){
  32. JOptionPane.showMessageDialog(null,"no value entered!");} //this line is not displayed when the text field is empty
  33. }
Add Comment
Please, Sign In to add comment