Tuesday, 17 January 2017

PROGRAM TO DELETE RECORD USING STATEMENT

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class Test8 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "rakesh");
Statement st = con.createStatement();
Scanner scan = new Scanner(System.in);
System.out.println("Enter Student Id");
int id = scan.nextInt();
String cmd = "delete from student_register where id="+id;
int count = st.executeUpdate(cmd);
if(count==1)
{
System.out.println("Record Successfully deleted");
}
else
{
System.out.println("Error/Invalid Student Id");
}
}
}

Output -
Enter Student Id
3
Record Successfully deleted

No comments:

Post a Comment