Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package myjava;
  2. import java.sql.*;
  3. import javax.swing.JOptionPane;
  4.  
  5. /**
  6. *
  7. * @author 3csd-14
  8. */
  9. public class GuiDelete extends javax.swing.JFrame {
  10. private Connection conn;
  11. /** Creates new form GuiDelete */
  12. public GuiDelete() {
  13. initComponents();
  14. conn=GuiMain.conn;
  15. try{
  16. Class.forName("com.mysql.jdbc.Driver");
  17. conn=DriverManager.getConnection(
  18. "jdbc:mysql://localhost/my3csd","root","12345"
  19. );
  20. statusTextArea.setText("Connection SUCCESSFUL!");
  21. }
  22. catch(Exception e) {
  23. statusTextArea.setText(e.getMessage() );
  24. }
  25. }
  26.  
  27.  
  28. private void deleteBActionPerformed(java.awt.event.ActionEvent evt) {
  29. // TODO add your handling code here:
  30. String sn = studnoField.getText();
  31. int ans=JOptionPane.showConfirmDialog(
  32. null,"Are you Sure?",
  33. "Exit?",JOptionPane.ERROR_MESSAGE
  34. );
  35. if(ans==JOptionPane.YES_OPTION){
  36. try{
  37. String SQL = "delete from students where studno= '" + sn +"'";
  38.  
  39. PreparedStatement stmt= conn.prepareStatement(SQL);
  40. stmt.executeUpdate();
  41. getContentPane().removeAll();
  42. initComponents(); //display back the components
  43. statusTextArea.setText("delete Successful!");
  44. }
  45. catch(Exception e){
  46. statusTextArea.setText( e.getMessage() );
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement