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 / November 2007

Tip: Looking for answers? Try searching our database.

Opening db connections

Thread view: 
Eduardo Yáñez Parareda - 13 Nov 2007 08:52 GMT
Hi,

when the connection to a DB is open, when you get the Statement or when you execute it?

ie.:

    Statement stmt = StatementProvider.getStatement();
    ResultSet rs = stmt.executeQuery("select 1");
    rs = stmt.executeQuery("select 1");
    rs = stmt.executeQuery("select 1");

Does this code mean 3 opened connection or only one (getStatement)?
Lew - 13 Nov 2007 13:35 GMT
> when the connection to a DB is open, when you get the Statement or when
> you execute it?

When you issue a DriverManager.getConnection(), typically, or via the
javax.persistence.EntityManager class.

> ie.:
>
[quoted text clipped - 4 lines]
>
> Does this code mean 3 opened connection or only one (getStatement)?

It's no more than one, but not being familiar with the StatementProvider class
it's hard to be sure.

What is StatementProvider?

Signature

Lew

Eduardo Yáñez Parareda - 13 Nov 2007 14:17 GMT
> It's no more than one, but not being familiar with the StatementProvider
> class it's hard to be sure.
>
> What is StatementProvider?

I'm sorry, it's a class of my project, I didn't realize of that.

This is what I meant:

Connection conn = .... getConnection...

Statement stmt = conn.getStatement();
ResultSet rs = stmt.executeQuery("select 1");
rs = stmt.executeQuery("select 1");
rs = stmt.executeQuery("select 1");
Lew - 13 Nov 2007 14:31 GMT
Lew wrote:
>> What is StatementProvider?

> I'm sorry, it's a class of my project, I didn't realize of that.
>
[quoted text clipped - 6 lines]
> rs = stmt.executeQuery("select 1");
> rs = stmt.executeQuery("select 1");

You have as many connections as conn points to.
<http://java.sun.com/javase/6/docs/api/java/sql/DriverManager.html#getConnection(
java.lang.String
)>

<http://java.sun.com/javase/6/docs/api/java/sql/Connection.html>

and, of course, the Javadocs for ResultSet and Statement.

BTW, consider using a PreparedStatement instead of a "regular" Statement.

Signature

Lew



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.