Solved

isClosed method of OracleConnection class

Posted on 2004-09-13
7
480 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 58
sumHeights2  challenge 7 78
How Complex Is This Java Course ? 9 63
pairs challenge 5 45
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now