• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

PreparedStatement - to use or not to use  RSS feed

 
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 ]
 
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
 
Author and ninkuma
Marshal
Posts: 66820
168
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
Boost this thread!