[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Maximum database connection Problem

Posted on 2006-07-06
6
Medium Priority
?
256 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
[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
  • 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 252 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 248 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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 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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

649 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