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 ]
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.