This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 email@example.com
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 firstname.lastname@example.org
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 />email@example.com<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>
Joined: Jan 03, 2002
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 firstname.lastname@example.org