Tuesday, 5 February 2013

PREPAREDSTATEMENT | Java J2EE Tutorial pdf

PREPAREDSTATEMENT

This is a subclass of the statement class: It compiles the SQL statement before execution and can also take parameters. Let’s say we need to execute the same query – for example select * from student where id=… - multiple times. The user IDs come from the userid[] array. If we use the Statement class, this SQL query will be compiled in each iteration of the loop, But in Prepared Statement the SQL statement is compiled only once and parameters are provided by the appropriate setXXX() method, depending on the data type of the underlying column. For example:
Table
ename         city
---------- ----------
Raj            bangalo
Output

Table, After Execution
ename          city
---------- ----------
Raj          bangalo
raj           chennai

No comments: