Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Pooling PreparedStatements

Thread view: 
Brzezi - 13 Jun 2005 22:04 GMT
Hi.

I`m programing an application, which uses database (Postgresql), it`s
multithread, there is no problem yet

it`s multithread, so I`v decided to use connection`s pooling, I had been
doing it before end there is no problem too, it works well

but problem appeared because I want to use PreparedStatements to execute
queries
for pooling connections I`m using org.apache.commons.dbcp, in its
configuration (BasicDataSource) is something about pooling prepared
statements, but how to use it?

when I want to gain Connection from pool I do:
dataSource.getConnection()

but how to do it for PreparedStatement, I mean how to gain
PreparedStatement from pool?
is preparedStatement.execute*() doing it itself? and I shouldn`t matter
about it no more?

If it is possible, please for a piece of source/example how I should do
it, because I`v not found anything useful on dbcp project website nor
google :/

Thanks in advance for any helpful idea.

Pozdrawiam
    Brzezi
Signature

[    E-mail: brzezi@enter.net.pl ][ MP3Blaster is playing now:                ]
[       Ekg: #3781111            ][ Title: Happy Home, Artist: 2Pac           ]
[ LinuxUser: #249916             ][ Album: Until The End Of Time, Year: 2001  ]
                                 [ Bitrate: 192kbit/s, Length: 3:56          ]

jonck - 14 Jun 2005 02:30 GMT
> Thanks in advance for any helpful idea.

Check out c3p0, a much easier to use connection pooling library than
dbcp with nice documentation. I have spent many futile hours with dbcp
in the past, switched to c3p0 and never looked back.

The project can be found here: http://sourceforge.net/projects/c3p0
JScoobyCed - 14 Jun 2005 07:37 GMT
>>Thanks in advance for any helpful idea.
>
[quoted text clipped - 3 lines]
>
> The project can be found here: http://sourceforge.net/projects/c3p0

Well, following your advice, I have used c3p0 in my benchmark plan. I
have a few comments:
1. c3p0 is not easier to use than Apache dbcp, I found it equally easy
2. execution time, memory usage, cpu: no differences between the two
libraries

I used JNDI connection in my server.xml (Tomcat).
Maybe I missed something...

--
JSC
jonck - 14 Jun 2005 14:21 GMT
> I used JNDI connection in my server.xml (Tomcat).
> Maybe I missed something...

The point is that C3p0 does not require JNDI, which for me was what was
the main struggle I was having with DBCP (could be that your troubles
lie elsewhere, but once I got the JNDI stuff working DBCP gave me no
more problems). Now the JNDI stuff is only difficult if you have a
standalone application (from your post I gathered that this is what
you're doing). If you're using Tomcat then DBCP works quite easy, since
Tomcat does the JNDI stuff for you.

Should you want to walk the JNDI path, a kind soul has helped me to get
this to work in the past. See
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_frm/thread/
6708485d8ca23fe0/d922a402dd4222b4?q
=
for instructions.

Kind regards, Jonck
JScoobyCed - 15 Jun 2005 10:12 GMT
>>I used JNDI connection in my server.xml (Tomcat).
>>Maybe I missed something...
[quoted text clipped - 13 lines]
>
> Kind regards, Jonck

Thanks for the reply.
I'm not sure to get what you say in:
"Now the JNDI stuff is only difficult if you have a standalone
application (from your post I gathered that this is what you're doing)"

I am working on a web application, using Tomcat as application server.

Now, I agree that if you are going to do a standalone application, it
might be more complex with DBCP than c3p0 :)

Thanks

--
JSC
Adam Maass - 14 Jun 2005 04:07 GMT
"Brzezi" <usunto.brzezi@enter.net.pl> wrote :
> Hi.
>
[quoted text clipped - 9 lines]
> configuration (BasicDataSource) is something about pooling prepared
> statements, but how to use it?

BasicDataSource bsd = ...
bsd.setPoolPreparedStatements(true);

But you may want a PoolingDataSource, not a BasicDataSource.

> when I want to gain Connection from pool I do:
> dataSource.getConnection()
[quoted text clipped - 3 lines]
> is preparedStatement.execute*() doing it itself? and I shouldn`t matter
> about it no more?

Precisely. Now a Connection.prepareStatement() actually fetches from the
pool if already created.

Some databases do not react well to pooling PreparedStatements. YMMV.

-- Adam Maass


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.