JDBC

JDBC Projects

JDBC Project 1

adplus-dvertising
JDBC Using Prepared Statement example–Delete a record using id
Previous Home Next
/* This program shows you how to delete a record from 
the database table using JDBC PreparedStatement.
In this example ,you give the id,that you want
to delete.*/

package r4r;
import java.sql.*;
import java.util.*;
public class DeleteData
{
public static void main(String[] args) {
try
{
Scanner s=new Scanner(System.in);
System.out.println("Enter id:-");
int s1=s.nextInt();
s.nextLine();
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.prepareStatement("delete
from user5 where id=?");
stmt.setInt(1, s1);
stmt.executeQuery();
System.out.println("successfully deleted");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

output:

Enter id:-
12
successfully deleted
Previous Home Next