Contact Us
JSP Tutorial
JDBC Tutorial
Book Must Read

JDBC Delete Records

Print   Email

To delete in table, we have to use DELETE sql command.

Delete records from table

In this form, we will delete records in staff_register table. First make database connection and fetch records which we have to delete and display on the form.

Example of Delete records from database through JSP
deleteRecord.jsp form get records from database and populates on this form for further deletion according to requirement. 

Database table

CREATE TABLE  staff_register (
  `iEmpID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sStaffName` varchar(60) DEFAULT NULL,
  `sStaffDept` varchar(45) DEFAULT NULL,
  `iStaffPhone` int(10) unsigned DEFAULT NULL,
  UNIQUE KEY `sStaffName` (`sStaffName`)


HTML Code Example

<%@ page language="java" import="java.sql.*" errorPage="" %>
        Connection conn = null;
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/DatabaseName","userName", "password");
        PreparedStatement psDeleteRecord=null;
        String sqlDeleteRecord=null;
            sqlDeleteRecord="Delete from staff_register where iEmpID=2";
        catch(Exception e)
          //// On error it will send back to addRecord.jsp page
        catch(Exception e)
Record is deleted successfully.

JDBC delete advance example




If You Like this Article, share this

  Privacy Policy