Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myjava;
- import java.sql.*;
- import javax.swing.JOptionPane;
- /**
- *
- * @author 3csd-14
- */
- public class GuiDelete extends javax.swing.JFrame {
- private Connection conn;
- /** Creates new form GuiDelete */
- public GuiDelete() {
- initComponents();
- conn=GuiMain.conn;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- conn=DriverManager.getConnection(
- "jdbc:mysql://localhost/my3csd","root","12345"
- );
- statusTextArea.setText("Connection SUCCESSFUL!");
- }
- catch(Exception e) {
- statusTextArea.setText(e.getMessage() );
- }
- }
- private void deleteBActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String sn = studnoField.getText();
- int ans=JOptionPane.showConfirmDialog(
- null,"Are you Sure?",
- "Exit?",JOptionPane.ERROR_MESSAGE
- );
- if(ans==JOptionPane.YES_OPTION){
- try{
- String SQL = "delete from students where studno= '" + sn +"'";
- PreparedStatement stmt= conn.prepareStatement(SQL);
- stmt.executeUpdate();
- getContentPane().removeAll();
- initComponents(); //display back the components
- statusTextArea.setText("delete Successful!");
- }
- catch(Exception e){
- statusTextArea.setText( e.getMessage() );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement