Re: How test Connection not valid?
- From: "kuassi.mensah@xxxxxxxxx" <kuassi.mensah@xxxxxxxxx>
- Date: 30 Sep 2006 16:13:34 -0700
I am aware that you might not be looking for a solution based on the
connection pool but the 10g JDBC connection pool (Implicit Connection
Cache) lets you validate the state of a connection it retrieves from
the pool before handing it to the application. You just need to set
ValidateConnection property to true. Check the JDBC 10g doc or chapter
7 of my book.
Kuassi.
Paolo wrote:
Hello,
I wrote a simple java program, where a Connection is created at the
beginning, and than is used to make queries to an Oracle DB (let me say
"a very very primitive connection pool").
When I run this program on a PC with only one ethernet card and
configured with only one LAN, if I disconnect LAN cable while program
is waiting "Press any key (q to exit)... " an than press a key, an
java.sql.SQLException (Connection reset by peer: socket write error) is
thrown.
But when I run this program on a PC with two ethernet card and
configured with two LAN (all active), if I disconnect LAN cable
(Connection created with this LAN) while program is waiting "Press any
key (q to exit)... " an than press a key, nothing happens, and program
wait forever!
I tried Oracle thin driver classes12.jar and ojdbc14.jar, but
conn.pingDatabase(10) returns everytime 0.
How can I test a Connection before use it?
Below a part of my code.
Thanks,
Paolo
try {
conn = DriverManager.getConnection(url, user, pwd);
BufferedReader stdin = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("\nPress any key (q to exit)... ");
while(!stdin.readLine().equalsIgnoreCase("q")){
st = conn.createStatement();
rs = st.executeQuery("select * from tab");
while (rs.next()) {
System.out.println(rs.getString("TNAME") + " - " +
rs.getString("TABTYPE"));
}
rs.close();
st.close();
System.out.print("\nPress any key (q to exit)... ");
}
}
.
- Follow-Ups:
- Re: How test Connection not valid?
- From: dohunt
- Re: How test Connection not valid?
- References:
- How test Connection not valid?
- From: Paolo
- How test Connection not valid?
- Prev by Date: Re: Connection to different databases from Oracle Java Stored Procedure
- Next by Date: Broken pipe exception
- Previous by thread: Re: How test Connection not valid?
- Next by thread: Re: How test Connection not valid?
- Index(es):
Relevant Pages
|
|