>> > Hello,
>> >
[quoted text clipped - 23 lines]
> thanks in advance.
> Els Wauters
You could use something like this:
public class ConnectionHolder {
private static Connection con;
public static Connection getConnection() {
if(con == null) {
con = //create the connection as you would otherwise
}
return con;
}
}
Now, everytime you need the connection, you do like this:
Connection con = ConnectionHolder.getConnection();
//work with the connection
This will break once you start to use your connection from within several
threads though. In that case, you'd have to setup a Datasource or a
ConnectionPool.

Signature
Kind regards,
Christophe Vanfleteren
Josef Garvi - 05 Apr 2004 07:31 GMT
> You could use something like this:
>
[quoted text clipped - 14 lines]
> Connection con = ConnectionHolder.getConnection();
> //work with the connection
Do you also need to close() the connection before terminating the app?

Signature
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
Christophe Vanfleteren - 05 Apr 2004 11:11 GMT
<snip code>
> Do you also need to close() the connection before terminating the app?
Yes, that would be the best thing to do.
You always need to close() the resources you use when using JDBC, so always
close your ResultSets, Statements and Connections.

Signature
Kind regards,
Christophe Vanfleteren
Simonne De Ryck - 05 Apr 2004 20:34 GMT
> You could use something like this:
>
[quoted text clipped - 14 lines]
> Connection con = ConnectionHolder.getConnection();
> //work with the connection
This application will be used on a network. So if I understand this
correctly I didn't start correctly.
What you mentionned about using an singleton I'm going to try one of these
days, when I have enough time.
Kind regards & thanks
Els Wauters
Josef Garvi - 22 Apr 2004 10:21 GMT
> This will break once you start to use your connection from within several
> threads though. In that case, you'd have to setup a Datasource or a
> ConnectionPool.
Any hints on how to do that?

Signature
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty