Solved

isClosed method of OracleConnection class

Posted on 2004-09-13
7
489 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

717 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