JDBC

JDBC Projects

JDBC Project 1

adplus-dvertising
JDBC Using Statement example – Update a record
Previous Home Next
/* This program shows you how to delete a
record from the database table using JDBC
Statement.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");
Statement stmt=con.createStatement();
stmt.executeQuery("delete from user5 where id='"+s1+"'");
System.out.println("successfully deleted");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

output:

Enter name:-
raghav
Enter id:-
1
successfully updated
Previous Home Next