Deletion of Database records from Java Frontend(JFrame)
First establish Database connection from Frontend ....
Here one can see Connection conn statement that I define in previous post simply copy from it nad
paste it...rest is delete function(delrec)..modify code to suit your needs...
public void delrec() throws Exception{
try {
Connection conn=getConnection();
PreparedStatement delrec= conn.prepareStatement("Delete from sch_db.student where st_id = ? ");
delrec.setString(1,Adm_No.getText());
delrec.executeUpdate();
}
catch(Exception ez){System.out.println(ez);}
finally {
JOptionPane.showMessageDialog(null, "Record Deleted","Delete Confirmation",JOptionPane.DEFAULT_OPTION);
//System.out.println("Record Deleted");
}}
When user Press Delete button after displaying desired record ...
JButton btnNewButton_2 = new JButton("Delete");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnNewButton_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try
{
delrec();
}
catch(Exception ex){System.out.println(e);}
finally {
System.out.println("Deletion Complete");
}
}
});
Next topic will be on Java Tips and tricks for faster development of application...
watch out...
Comments
Post a Comment