How to re-use a PreparedStatement from poolled connections?

Consider poolled connections....
one advantage of poolled connections are resource sharing...preventing the system from creating lots of connections or from creating and destroying similar connections.
Connection and thread pools are specially usefull on multi-threaded servers.
Consider now an application that has a service that logs the number of times a user has connected.
This service is thread-safe, it is synchronized (bad) or it doesn�t have state (good).
Every time a thead is started in this service a connection is requested from the pool que the service finish logging it needs to release the connection back to the pool.
This is done automatically by the Connection wrapper. When we do conn.close(); actually the wrapper is releasing the connection so that other threads and services can use it.
Suppose the log service uses this PreparedStatement: "Update users set accessCount=accessCount+1 where userId=?"
Because we are using connection pooling, every time the service is requested we possibly get a different connection object. Then, we can�t store a PreparedStatement object locally.
If we use a conn.prepareStatement, then we are creating a new PreparedStatement on every request. Isn�t it? Then, we are not able to re-use PreparedStatements.
Does anyone know a pratical way to re-use PreparedStatements in a multi-threaded server? In my case, this is a servlet.
Thanks

I can only speak about DB2 on the ISeries (AS/400) but to get the benifits of prepared statments it is not required to leave the preperedstatment object open. The first time a prepared statment is prepared against a connection: it takes a significant amount of time, subsiquent prepares for exactly the same SQL take practically no time.
It may be different on with your database and driver but you should have a test!
So if this is the case it is not a problem to create and close a prepared statment with every request, you will get the preformance increase after the 1st time the statment is prepared against the connection in question.
Hope this helps!

Similar Messages

  • How can I use LDAP searching from OSX Lion Server to Mozilla Thunderbird?

    How can I use LDAP searching from OSX Lion Server to Mozilla Thunderbird?  We have a super awesome contacts server that works great for our Mac users.  About 30% of our company are on PCs, and I would like to use the Mozilla Thunderbird mail client for them.  I see that in Thunderbird I can set up LDAP searching, and would like to have this feature point to our contacts server.  I've tried several different settings, and looked all over the web, but could not find the proper way to configure this.  Does anyone know if this can be done, or if not, would have a better suggestion?  Thank you for your time!!

    try double clicking keychain acces should launch and ask if you want to install login, system, System roots
    A dialog box will launch asking where to install the cert since your configuring a vpn I would put the certificate it in system.

  • I can not find my playlists on apple tv. How can I use my playlists from itunes on apple tv ?

    I can not find my playlists on apple tv. How can I use my playlists from itunes on apple tv ?

    Hey luisathome,
    Thanks for the question. The following resource outlines how to setup Home Sharing between your Apple TV and computer:
    iTunes 11 for Mac: Play items in your iTunes library using Apple TV (2nd generation or later)
    http://support.apple.com/kb/PH12153
    Thanks,
    Matt M.

  • How can I use a pic from iPhoto as a background for a page, How can I use a pic as a background for a page

    How can I use a pic from iPhoto as a background for a page, How can I use a pic as a background for a page

    cd,
    Insert the picture and position it as you desire
    Make sure the picture is set to Floating in the Wrap Inspector
    Arrange > Send Objects to Background
    Regards,

  • How do i use a tune from my itunes as a ringtone on my iphone

    how do i use a tune from my i tunes as a ringtone on my iphone 4g

    Instructions for both Windows and Mac users at this link:
    http://www.wikihow.com/Make-Ringtones-for-the-iPhone

  • HT4427 how do I use a song from iTunes as the ringtone for my iPhone 5?

    how do I use a song from iTunes as the ringtone for my iPhone 5?

    Google will find several free ways to create ringtones for iphone.

  • How to I use a music from my music as a ringtone on my iphone4s?

    How to I use a music from my music as a ringtone on my iphone4s?

    You can create custom ringtones with music in your iTunes library on your computer that does not include DRM protection. If you have a Mac running Snow Leopard or later, Apple includes at least one 3rd party app via the App Store for a Mac for creating custom ringtones. The one I've used is called Ringer, and I believe it was free or cost a couple of bucks. Creates the custom ringtone from your designated section of the song and places the ringtone in the appropriate location in your iTunes library to be selected under the Ringtones tab for your iPhone sync preferences with iTunes to be transferred to your iPhone.
    I'm sure there are some free and paid 3rd party apps that provide the same for Windows.

  • How can i use migration assistant from a Power PC G4 powerbook?

    How can i use migration assistant from a Power PC G4 laptop that can't run 10.5 to a new mini running Lion? Mini's MA says I have to upgrade the laptop's MA but the upgrade requires 10.5 as a minimum
    help,please
    jan

    That is correct. You'll need either an ethernet cable or a firwire cable and a firewire to thunderbolt adapter to connect the two macs together. Here's info on Migration/Setup assistant
    http://support.apple.com/kb/HT4889?viewlocale=en_US&locale=en_US

  • HT5467 how can i use location services from my pc to find my lost ipod?

    how can i use location services from my pc to find my lost ipod?

    Find My iPod
    http://www.apple.com/sg/icloud/features/find-my-iphone.html

  • How can I use my camera from sony xperia z2 on my laptop

    How can I use my camera from sony xperia z 2 on my laptop? Please help me Thanks!

    You need an app, something like this 
    https://play.google.com/store/apps/details?id=com.busywww.cameraremote&hl=en

  • How can i use my iPhone 4 and connect via bluetooth with my macpro

    how can i use my iPhone 4 and connect via bluetooth with my macpro

    The only way that you can connect your iPhone to the mac is to use it for a "Wi-fi hotspot" meaning that you can use the celluar connectivity of your phone to connect your computer to the interent.
    Do you mean a MacBook Pro of the desktop MacPro?

  • How to migrate  the data flow from DB CONNECT sourse system from 3.5 to BI

    Hi
    can any one tell me how to migrate the data flow from DB CONNECT sourse system from 3.5 to BI 7.

    Hi,
    Go to Infoprovider to which your DB connect DS feeds and Right Click on Data source-> Then Migrate-> With Export---> You have to build new 7.0 Transformations and DTP's etc.
    ~AK

  • How can I use the photos from iphoto to display in contacts?

    Contacts has a space for a photo.  At one time I knew how to populate this space with photos from iPhoto. Currently my choices are to use an icon or take a pic with the camera.
    How can I add the photos from iPhoto to the choices for populating the "Contacts" image space for individual cards?

    See this Discussion...
    https://discussions.apple.com/message/19082703#19082703

  • How do  I use a variable from an Interface class?

    Right now I have three classes. First class is called Game and it extends my second class call Parent and also implements my third class call Source. Source is an interface class. I have a variable that I want to use in my Source class named Checker. Now, How do I go among using that variable from my Game class? What should the code look like?
    ex.
    public class Game extends Parent implements Source
    need help badly....

    ok, what I forgot to tell you guys is that my variable
    in my interface class is a boolean type(true or
    false). It is set to true now. But I want it to change
    to false when a user triggers a button in the Game
    class. How do I do this? You don't because you can't. If you have a varaible declared in an interface it must be static and final. It cannot, therefore, be changed. Better head back to the drawing board.

  • How can I use the speakers from my old iMac (with miniRCA? plug) on a new iMac

    How can I use the speakers (M-Audio) from my old 24" iMac on a new 27" iMac?  There is no jack on the new iMac - is there an adapter that will use the mini-RCA (?) plug from my old speakers to connect them to a new iMac?  Thanks ...

    Thanks again!
    Hmmm ... I wonder.  The input jack for external speakers quit working on my old iMac (it made lotsa static noise for a while when I moved the plug or computer, then quit working completely; I figure something inside the computer got loose or crapped out - and I'm too cheap/lazy to take it the 20 miles to the nearest shop that might fix it).  When I plug the speakers into the headphone jack on the old iMac, I get very low volume or just one channel.
    I don't have the new iMac yet, but I was hoping to use these old speakers instead of buying new ones.  I will certainly try your solution - what do I have to lose?  If they don't work, then I get new ones - or try something else.
    Many thanks for your time!

Maybe you are looking for