• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement - to use or not to use

 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have few DAO methods for data fetch - each method has just one query which will be executed only once (it doesn't have multiple inputs for which that query needs be excuted with different sets of inputs during one call to this method).

Then next time, that DAO Method gets called, it recreates the SQL query with new set of inputs and executes it.

In this situation, would using PreparedStatement instead of regular Statement buy me anything? I mean, If I use PreparedStatement, does the compiled statement stay in database memory for the next time around when that method and ultimately same query (but with different inputs) is called?

I guess short question is who pre-compiles PreparedStatemnt and where does it get stored and in what form?

Thanks,
P.Ingle
[ May 19, 2005: Message edited by: p Ingle ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are longer discussions if you search the forum, but as long as the database supports caching statements, the statement gets stored in the database against the string value. Depending on the database you use, it may be case-sensetive so it is worth making sure you always create the same String for the SQL.

Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google for the term 'SQL injection'.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic