Solved

Maximum database connection Problem

Posted on 2006-07-06
6
230 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JUnit 4 @Before and @BeforeClass differences 3 59
Oracle SQL syntax check  without executing 6 50
javap not working 8 44
mysql jsp example issue 32 33
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

776 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