| Author |
Statement vs PreparedStatement
|
Santosh Kumar
Greenhorn
Joined: Jan 03, 2002
Posts: 28
|
|
Hi All, Can any one list me all the differences between Statement and PreparedStatement.I want to know also one more thing like how PreparedStatement is better than Statement when there is time to save memory space of the database. thank you regards santosh kumar san19@indiatimes.com
|
Santoh Kumar<br /> India<br />SCJP 1.4 <br />SCWCD 1.4
|
 |
John Carnell
Author
Ranch Hand
Joined: Sep 27, 2002
Posts: 71
|
|
Originally posted by sare san: Hi All, Can any one list me all the differences between Statement and PreparedStatement.I want to know also one more thing like how PreparedStatement is better than Statement when there is time to save memory space of the database. thank you regards santosh kumar san19@indiatimes.com
Hi Santosh, A preparedstatement pre-parses and pre-compiles the SQL statement so that when the SQL code is executed multiple times it will not have to be re-parsed each time. This is more efficient then a Statement object because a statement object will cause the database to re-parse the SQL statement every time a command is executed. This saves times because parsing SQL code does take time on the database side. This might not seem like a lot of a overhead in a low transaction-volume application, but in a high transaction environment, this can represent a significant amount of overhead as the same SQL statements have to be parsed over and over again. In addition, the PreparedStatement class allows you to "parameterize" your SQL statement so that you do not have to build the SQL statement parameters by "hand." Each parameter is represented by a question mark and can be replaced by calling the appropriate set() method on the PreparedStatement class. In a Statement object the parameters have to be built as part of the SQL statement. I hope that helps. Thanks, John Carnell
|
John Carnell<br />Principal Architect<br /> <br />Netchange, LLC<br />1161 HillCrest Heights<br />Green Bay, WI 54313<br /> <br />john.carnell@netchange.us<br /> <br /> <br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/159059228X/ref=jranch-20" target="_blank" rel="nofollow">Pro Jakarta Struts, Second Edition</a>
|
 |
Santosh Kumar
Greenhorn
Joined: Jan 03, 2002
Posts: 28
|
|
Thank you for prompt reply. Sir I have again one Question? Whatever you said i understood but for Statement I have still confusion like whether it compiles and parses everytime for every request or only parses everytime. And one more question whether on parsing the statement it takes any memory space on the database side or not. regards santosh kumar san19@indiatimes.com
|
 |
 |
|
|
subject: Statement vs PreparedStatement
|
|
|