Google News
logo
JDBC - Interview Questions
What are the types of JDBC statements?
Statements are useful for sending SQL commands to the database and receiving data from the database. There are three types of statements in JDBC. They are :
 
Statement : It is the factory for ResultSet. It is used for general-purpose access to the database by executing the static SQL query at runtime.
Statement st = conn.createStatement( );
ResultSet rs = st.executeQuery();
PreparedStatement : It is used when we need to give input data to the query at runtime and also if we want to execute SQL statements repeatedly. It is more efficient than a statement because it involves the pre-compilation of SQL.
String SQL = "Update item SET limit = ? WHERE itemType = ?";
 PreparedStatement  ps = conn.prepareStatement(SQL);
 ResultSet rs = ps.executeQuery();
CallableStatement : It is used to call stored procedures on the database. It is capable of accepting runtime parameters.
CallableStatement cs = con.prepareCall("{call SHOW_CUSTOMERS}");
ResultSet rs = cs.executeQuery();

 

Advertisement