Example : How to Delete/Remove data or a single record from an Oracle 10g/11g database using NetBeans 8.2?
// Write Java-Oracle 10g Connectivity Code here first properly/globally.
try {
String studentId = txtStudentId.getText();
if(studentId.equals(""))
{
JOptionPane.showMessageDialog(this,
"Enter Student ID");
return;
}
int confirm = JOptionPane.showConfirmDialog(
this,
"Are you sure to delete this record?",
"Confirm Delete",
JOptionPane.YES_NO_OPTION);
if(confirm == JOptionPane.YES_OPTION)
{
String sql =
"DELETE FROM student_register WHERE student_id=?";
PreparedStatement pst =
conn.prepareStatement(sql);
pst.setString(1, studentId);
int i = pst.executeUpdate();
if(i > 0)
{
JOptionPane.showMessageDialog(this,
"Record Deleted Successfully");
resetForm();
}
else
{
JOptionPane.showMessageDialog(this,
"Record Not Found");
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,
"Delete Error : " + e);
}
}
------------------------------- 2nd Method -----------------------------------
// Write Java-Oracle 10g Connectivity Code here first properly/globally.
private void jBtnRegDeleteActionPerformed(java.awt.event.ActionEvent evt)
{
String UID = jTxtRegUname.getText().trim();
try
{
pst=conn.prepareStatement("delete from REGISTRATION where REGUNAME = '"+UID+"'");
pst.executeUpdate();
//out.println("Data Delete Succefully....");
showMessageDialog(null,"Data Delete Successfully....");
}
catch(Exception e)
{
System.out.println(e);
}
}
![]()
0 Comments