Solved

Maximum database connection Problem

Posted on 2006-07-06
6
208 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
Comment Utility
if the db is not then you cannot get a connection to it. it will throw an exception.
0
 

Author Comment

by:ruby_srinivas
Comment Utility

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
Comment Utility
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
Comment Utility
> 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Unable to open debugger port in Intellij idea 6 77
network + 7 72
countHi2 challenge 7 42
bitbucket vs gitbucket 3 28
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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.

728 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

11 Experts available now in Live!

Get 1:1 Help Now