Re: How test Connection not valid?



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)... ");
}
}

.



Relevant Pages

  • RE: Connection pooling
    ... Connection Pooling with SQL Server 2000 Analysis Services ... the Microsoft XML for Analysis Provider to develop scalable client and Web ... applications for Microsoft SQL Server 2000 Analysis Services. ... Balancing and Shrinking the Connection Pool ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL Compact Edition - Connection Pool --> Slow!
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... mind (--> get a connection, use it and release it as soon as possible ... about the connection pool for Compact Edition 3.1. ...
    (microsoft.public.sqlserver.ce)
  • Re: SQL Compact Edition - Connection Pool --> Slow!
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... mind (--> get a connection, use it and release it as soon as possible ... about the connection pool for Compact Edition 3.1. ...
    (microsoft.public.sqlserver.ce)
  • Re: ASP.NET SQL Processes
    ... Microsoft Online Support ... when we use the ADO.NET's connection ... | connection pool, when we create SqlConnections, the ADO.NET will retrieve ... | | SQL server doesn't keep any processes attached to the application. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Db connexion mode ???
    ... the Connection pool is created ... Hitchhiker's Guide to Visual Studio and SQL Server ... create 5 different connection string that will be aplce in the pool ( ...
    (microsoft.public.sqlserver.connect)