wood burning stoves 2.0*
The moose likes JDBC and the fly likes Best way to use connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Best way to use connection" Watch "Best way to use connection" New topic
Author

Best way to use connection

Nandhakumar Soundarrajan
Greenhorn

Joined: Apr 24, 2009
Posts: 23
Hello JAVA experts,

I am in a process of developing a web application. I am just thinking of what would be the best way to use Connection object.

I am currently adding the connection object to the user's session and using it, but I encounter some problem (Connection is busy error) when I execute a query inside a while loop of the resultset of the first query, so in those cases, I am creating a new connection and executing the outer query, so that the inner query can use the connection object from the Session.

Could you guys give me a better in sight on how to handle this?

I am using jdbc odbc bridge to connect to my SQL server.

Note, I am not facing any issues with the code when I was using Ms-Access as a database.

Thanks,
Nandha Kumar S.

Thanking the green horns sincerely,
Nandha
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

First off, don't use the JDBC-ODBC bridge, it is not production quality. Use a proper type 4 driver instead.

Secondly, a better solution in a web application is to use a connection pool, which gives you a nive configurable way of sharing connections.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nandhakumar Soundarrajan
Greenhorn

Joined: Apr 24, 2009
Posts: 23
Hi Paul,

Thanks for your reply.

Now I changed my code to use "Microsoft SQL driver for JDBC" and this is a type 4 driver.

And also, using connection pooling.

Thanks for your time.
Steve Jefferson
Greenhorn

Joined: Jul 09, 2009
Posts: 10
I think Paul is right. Have you got the solution?


Project Management Tool | Automatic Scheduling
Nandhakumar Soundarrajan
Greenhorn

Joined: Apr 24, 2009
Posts: 23
Yes, I have implemented connection pooling and used type4 driver.

Thanks you guys...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best way to use connection
 
Similar Threads
On DB Connections, MVC2, and Sessions
When to use session beans...
two versions for filling the report, whhch one is the best??
Alter session to set NLS_CALENDAR = 'Persian'
Values not retrieved from the DB