Solved

isClosed method of OracleConnection class

Posted on 2004-09-13
7
486 Views
Last Modified: 2007-12-19
I use the isClosed method in atest java class.
In a while(true) loop I call is closed and print its value.

When I run the class and see the output the value printed is always false. In between if I restart the datbase, still  the value printed is false (whioch actually should be true).

How do I know that the connection is no longer valid before I fire a query.Does this isClosed method help?

Thanks
Regards
JAs
0
Comment
Question by:jas123
7 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 168 total points
ID: 12051817
isClosed:

This method is guaranteed to return true only when it is called after the method Connection.close has been called.
This method generally cannot be called to determine whether a connection to a database is valid or invalid. A typical client can determine that a connection is invalid by catching any exceptions that might be thrown when an operation is attempted.

0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 166 total points
ID: 12051822
What application server are you using? Some of them test conenction occasionalyl and if no longer valid they assign a new one from the connection pool.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12051829
That's a quote from the Java SDK Help about java.sql.Connection.isClosed()
You can read it also at http://www.jguru.com/faq/view.jsp?EID=391332
0
 
LVL 7

Expert Comment

by:grim_toaster
ID: 12051898
This is pretty much the same question as you asked previously, complete with some good answers:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21121095.html
0
 
LVL 9

Assisted Solution

by:Venci75
Venci75 earned 166 total points
ID: 12052185
execute this code when returning the connection to the pool:

try {
   if (OracleConnection.pingDatabase(0) != 0) {
      // not a valid connection
   }
} ctach (SQLException sqlex) {
      // not a valid connection
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 106
eclipse buid path vs tomcat lib path 10 34
by zero exception 10 53
Is there a simpler dropbox system? 10 35
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question