• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement vs PreparedStatement

 
Santosh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John Carnell
Author
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Santosh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic