Sei sulla pagina 1di 1

 once it is clicked a JOptionInputDialog will appear

Once the ID Number was entered it will be automatically deleted from the database

CODE for the Delete Button

Note: Regards that the import java.sql.*; and import javax.swing.*; is already on the top of the public class….

private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {

String id=JOptionPane.showInputDialog(null,"Enter Product ID You want to delete","Commonwealth High


School",JOptionPane.INFORMATION_MESSAGE);

try{

Connection kon;

ResultSet rs;

Statement stmt;

String query;

String url= "jdbc:odbc:konekted";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

kon = DriverManager.getConnection(url, "", "");

stmt = kon.createStatement();

String qry="Select * FROM TblProducts WHERE PROID='"+id+"'";

rs = stmt.executeQuery(qry);

if(rs.next())

query = "DELETE FROM TblUsers WHERE PROID='"+id+"'";

int j = stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Successfully Deleted "+j,"Commonwealth High


School",JOptionPane.INFORMATION_MESSAGE);

else

JOptionPane.showMessageDialog(null,"No data found ","Commonwealth High


School",JOptionPane.ERROR_MESSAGE);

stmt.close();

kon.close();

catch(Exception e){}

Potrebbero piacerti anche