?
Solved

will the while break out of the loop or do i need another if

Posted on 2006-06-21
3
Medium Priority
?
205 Views
Last Modified: 2010-03-31
i am concerned with this method.

if my counter reaches 4 i want it to terminate the application
not just break out of the while loop and go on with the code

do i need a break in the while or do i need an if to say if counter is greater than 4 System.exit???

thanks in advance annie



      public static Connection getDbConnection(String USERIDin, String PWDin, String SERVERin)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, InterruptedException
      {
            int dbctr = 0;
            while(dbctr <= 3)//do i need another if to say if it reaches 4 kill ps???
            {
                  try
                  {
                        Class.forName(COM_IBM_DB2_JDBC_APP_DB2DRIVER).newInstance();
                        conn = DriverManager.getConnection(JDBC_DB2 + SERVER, USERID, PWD);
                  }
                  catch(Exception e)
                  {                        
                        dbctr++;
                        
                        logError();
                        
                        try
                        {
                              Thread.sleep(10000);
                        }
                        catch(InterruptedException ie)
                        {
                              throw ie;
                        }
                  }
            }
            return conn;
      }
0
Comment
Question by:annie613
[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
3 Comments
 
LVL 14

Accepted Solution

by:
StillUnAware earned 200 total points
ID: 16950874
That code should be:

public static Connection getDbConnection(String USERIDin, String PWDin, String SERVERin)
          throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, InterruptedException
     {
          int dbctr = 0;
          while(dbctr <= 3)//do i need another if to say if it reaches 4 kill ps???
          {
               try
               {
                    Class.forName(COM_IBM_DB2_JDBC_APP_DB2DRIVER).newInstance();
                    conn = DriverManager.getConnection(JDBC_DB2 + SERVER, USERID, PWD);
                    return conn;
               }
               catch(Exception e)
               {                    
                    dbctr++;
                   
                    logError();
                   
                    try
                    {
                         Thread.sleep(10000);
                    }
                    catch(InterruptedException ie)
                    {
                         throw ie;
                    }
               }
          }
          System.exit(1); //some error code
          return null;
     }
0
 

Author Comment

by:annie613
ID: 16950890
sometimes having another set of eyes and ideas is a great advantage, i didnt even think about putitng the return conn in the try and that is what i was fearing about using the while loop. thanks for your help CHEERS
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16950898
glad to help
0

Featured Post

Independent Software Vendors: 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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