Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 28th, 2002, 09:32 AM
markhorgan markhorgan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Salford, UK
Posts: 0 markhorgan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Statement v's PreparedStatement

PreparedStatement makes sense if you are doing a lot of SQL calls but I was wondering is there any advantage in using it over Statement when you're just making one SQL call. The reason I'm asking is that I read somewhere that PreparedStatements are saved so I was wondering does the JVM save all PreparedStatements over an application's lifetime and if it comes across a piece of SQL it has already prepared will it re-use it even if the actual preparedStatement object is long out of scope?

Reply With Quote
  #2  
Old February 28th, 2002, 05:14 PM
oscagne oscagne is offline
Java Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 5 oscagne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The idea with a prepared statement is that you can set the query but vary the parameters you pass in. With a statement you have to prepare it dynamically each time. So if for example you wanted a page to insert the content of a form into the db each time it is called then it would be far easier to declare a preparedstatement once and the fill it with the relevant data, than to instatiate a new one each time. Instantiation is an expensive (in terms of time) operation, so multiple instantiation vs a single preparedstatement would be a lot faster.

The next step along is to create callablestatments and get them to call database stored procedures which will be faster as they will be precompiled in the database, and have far more flexibility aswell

Was that any help?

Oscagne

Reply With Quote
  #3  
Old March 1st, 2002, 03:47 AM
markhorgan markhorgan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Salford, UK
Posts: 0 markhorgan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for that So if I wanted to use a PreparedStatement across multiple users/threads I would have to declare it as a field of the servlet/JSP page rather than a local method variable.

Reply With Quote
  #4  
Old March 1st, 2002, 07:17 AM
oscagne oscagne is offline
Java Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 5 oscagne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yeah, just put it as a static member variable

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Statement v's PreparedStatement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway