Create Table::
SQL> create table test1(eid int,ename varchar2(10));
Table created.
SQL> insert into test1 values(1,’vijay’);
1 row created.
SQL> insert into test1 values(2,’rajesh’);
1 row created.
SQL> select * from test1;
EID ENAME
— — — — — — — — — —
1 vijay
2 rajesh
SQL> commit;
Commit complete.
import java.sql.*;
class Test {
public static void main(String[] args) throws Exception {
//load JDBC driver
//get connection
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "system", "tiger");
//create statement obj
Statement st = con.createStatement();
//prepare and execute query
String query = "delete from test1 where eid=2";
int count = st.executeUpdate(query);
if (count == 0) {
System.out.println("No Row is deleted");
} else {
System.out.println(count + "Row are deleted");
}
con.close();
}
}
After Code execution
SQL> select * from test1;
EID ENAME
— — — — — — — — — —
1 vijay