Q) Develop a JDBC application that deletes all the employees from the db. Make use of pure JDBC approach of connectivity
A)
import java.sql.*;
class EmplyeeRemoval {
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:server","scott","tiger");
Statement st = con.createStatement();
int rc = st.executeUpdate("DELETE FROM EMPLOYEE");
System.out.println(rc+"employees are fired");
st.close();
con.close();
}
}
Explanation:
->in the above program execute operation is a method call that is called by main method. The main method calling the execute Update method on the statement object.
->when the deletion statement is executed the all rows are deleted in the database. But in the DML commands are saved when we executed commit; statement in the oracle prompt but we are not used commit; statement in the java program. Because the connection is opened in the auto connection enabled mode.
->“auto connect enabled mode” the connection is opened so that’s why changes are maid permanently.
->”clear scr” is used to clear the oracle prompt.
Comments
Post a Comment