Solved

Maximum database connection Problem

Posted on 2006-07-06
6
241 Views
Last Modified: 2010-03-31

Hi,

I am using a middle ware integration tool which gets connected to oracle database.

But in the code(Java) there is no where that we are trying to close the result set and the connections . The conenctions are always open.

When the DB is down, still the tool assumes the DB is up and tries to hit the database again and again increasing the number of connections. Once it reaches to the highest level the whole DB is down.

So I just want to know is there any way in java which verifes the connection is up or not  . if the DB is not up we try to connect to the database for three time or may four times, if by that time DB is up it should get connnected  other wise we ask it to sleep for say 3 hours and then try again..

Please help me with this situation.

Srini
0
Comment
Question by:ruby_srinivas
  • 2
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17054996
if the db is not then you cannot get a connection to it. it will throw an exception.
0
 

Author Comment

by:ruby_srinivas
ID: 17055051

Yes thats right I get an exception saying that Oracle is not avaliable. But I wan to restrict the number of times it tries to connect to the DB , Say only 4 times and even then if DB is not up then it should sleep for 3 hours and try again..

Srini
0
 
LVL 92

Accepted Solution

by:
objects earned 63 total points
ID: 17055075
count the number of times u get an exception

Connection getConnection()
{
   Connection c = null;
   int attempts = 0;
   while (c==null && attempts<3)
   {
       try
       {
           c = ....  // attempt to get a connection
       }
       catch (Exception ex)
       {
          attempts++;
       }
     }
   }
}
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 62 total points
ID: 17056110
> When the DB is down, still the tool assumes the DB is up and tries to
> hit the database again and again increasing the number of connections.
> Once it reaches to the highest level the whole DB is down.

Could not understand this... if db is down, you will not get the connection.
If you are getting the connection - the implementation of the connection-pool
is wrong. It should NEVER increment the no of connection if db is down.

You may want to try commons-dbcp framework as connection pooling framework:
http://jakarta.apache.org/commons/dbcp/
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 241
how to see all occupied ports on windows 10 laptop 15 84
How to execute a Python program and gather return output in Java 2 49
ejb mdb examples 1 21
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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 …

726 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