Delete Account Source Code
Delete Account Source Code
*;
//import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
Container con;
Connection cn;
Statement st;
ResultSet rs;
frame = fr3;
this.st = st3;
con = getContentPane();
con.setLayout(null);
lbl_ano.setBounds(10,5,100,25);
con.add(lbl_ano);
txt_ano.setBounds(130,5,75,25);
con.add(txt_ano);
txt_ano.setEditable(false);
lbl_fname.setBounds(10,35,100,25);
con.add(lbl_fname);
txt_fname.setBounds(130,35,150,25);
con.add(txt_fname);
txt_fname.setEditable(false);
lbl_lname.setBounds(10,65,100,25);
con.add(lbl_lname);
txt_lname.setBounds(130,65,150,25);
con.add(txt_lname);
txt_lname.setEditable(false);
lbl_uname.setBounds(10,95,100,25);
con.add(lbl_uname);
txt_uname.setBounds(130,95,150,25);
con.add(txt_uname);
txt_uname.setEditable(false);
lbl_pword.setBounds(10,125,100,25);
con.add(lbl_pword);
txt_pword.setBounds(130,125,300,25);
con.add(txt_pword);
txt_pword.setEditable(false);
btn_search.setBounds(10,175,110,50);
con.add(btn_search);
btn_delete.setBounds(130,175,110,50);
con.add(btn_delete);
btn_exit.setBounds(250,175,110,50);
con.add(btn_exit);
btn_search.addActionListener(this);
btn_delete.addActionListener(this);
btn_exit.addActionListener(this);
btn_delete.setEnabled(false);
pack();
setSize(500,300);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
btn_delete.setEnabled(true);
btn_search.setEnabled(false);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage(),"Message",
JOptionPane.ERROR_MESSAGE);
}
}
if(evt.getSource()==btn_delete)
{
try
{
dbOpen();
String c = txt_ano.getText();
txt_ano.setText("");
txt_fname.setText("");
txt_lname.setText("");
txt_uname.setText("");
txt_pword.setText("");
dbClose();
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage(),"Message",
JOptionPane.ERROR_MESSAGE);
}
}
if (evt.getSource() == btn_exit)
{
this.dispose();
}
}
public void dbOpen()
{
try
{
String url="jdbc:mysql://localhost:3306/javaee_db";
String user="root";
String password="";
cn=DriverManager.getConnection(url,user,password);
st=cn.createStatement();
rs = st.executeQuery("select * from accounts_tbl");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
}
}