1

I know this is very similar to questions already answered, but there is a slight variation.

I have a list of connections in my production connection setup. The process is to start with the first and keep trying till I get a connection. I would like to be able to run a task that used this same list as its input, but did just enough to show which of the connections will be used by the application. To avoid our security team getting all upset, this would have to be done without the username/password.

Is it possible?

3
  • Not that I know of, nor should it be. I don't see why you need anything beyond what every connection pool provides. Commented Aug 3, 2015 at 10:23
  • @Rajesh, I was hoping for a pure java solution, as then it would fit in with a pre-existing application that checks similar details using dns lookups Commented Aug 3, 2015 at 10:55
  • Also, "TNSPING attempts to contact the corresponding listener. It does not actually determine whether the database is running." (Quoting @Rajesh's link.) So it wouldn't be a solution anyway. Commented Aug 3, 2015 at 11:33

1 Answer 1

1

Below answer may be helpful to you. getErrorCode() method in SQLException returns 1017 value on authentication failure. So you can iterate through list of connections and invoke validateConnection.

  • I'm using dummy username and password here (I don't see any other option)
  • Replace host, port and SID values.

    public static void main(String[] args) {
        String connString = "jdbc:oracle:thin:@host:port:SID";
        System.out.println(validateConnection(connString));
    }
    
    public static boolean validateConnection(String connString) {
    
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection(connString, "x", "y");
        } catch (SQLException sqle) {
            if (sqle.getErrorCode() == 1017)
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        return false;
    }
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.