Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

PreparedStatement - to use or not to use  RSS feed

Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?

[ May 19, 2005: Message edited by: p Ingle ]
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.

Posts: 67226
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'.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!