In this tutorial, you will be able to learn to delete the data stored in SQL database using Java.
Please watch the video because there are some task to be done beside code
Code to Delete data from sql server in Javaprivate void deleteBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=testdb;user=sa;password=orchid";
Connection con = DriverManager.getConnection(url);
int row= jTable_Display_User.getSelectedRow();
String value=(jTable_Display_User.getModel().getValueAt(row, 0).toString());
String query="DELETE FROM users where sno="+value;
PreparedStatement pst = con.prepareStatement(query);
pst.executeUpdate();
DefaultTableModel model = (DefaultTableModel)jTable_Display_User.getModel();
model.setRowCount(0);
show_user();
JOptionPane.showMessageDialog(null,"Deleted Successfully!");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
Please don't forget To Like, Share and Subscribe my Youtube video and Channel.
Youtube Channel Subscription Click Here
No comments:
Post a Comment