|
Answer» 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. Example:
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. Example:
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. Example:
CallableStatement cs = con.prepareCall("{call SHOW_CUSTOMERS}");ResultSet rs = cs.executeQuery();
|