0

I am working to test if a mysql database is up and running. I need to do this with the help of ip , portNumber and schemaName and no username/password.

So i need to validate the connections of a database schema with the help of:

IP (hostname)
Port
DB Schema

(I will not be having username and password)

Have successfully implemented a solution for this but not able to figure out how to do the same without username/password.

Here is my current solution:

public static void checkDBstatus(){
        try{

        java.sql.Connection connect = DriverManager.getConnection("jdbc:mysql://10.10.200.xxx:3416/schemaName","username", "password");

        System.out.println(connect.isClosed());

        }catch(Exception exp){
            exp.printStackTrace();
        }
        }
4
  • Hope this link helps stackoverflow.com/questions/17208937/… Commented Nov 29, 2015 at 11:38
  • You might create a user just for pinging the database which is not granted for any table. Or you may leave the username/password away, if there's a server answer like "bad credentials", the server must be up and running. Commented Nov 29, 2015 at 11:46
  • 1
    It does not make any sense to do this. If the connection can not be established, an exception will be thrown anyway. And even if your connection is alive at the beginning, there is no guarantee that it will be available in the future. If you try to do a query on a stale connection, an exception will be thrown, too. Handle them accordingly and Bob's your uncle. Commented Nov 29, 2015 at 11:53
  • thanks for suggestions. i will handle it in a way that if i get user not authorized or bad credentials, will assume it to pass. any other error, exception, will mark it as fail Commented Nov 30, 2015 at 3:37

1 Answer 1

0

i do not think there is a way to connect MySql databases without username or password.

at least, All the methods in DriverManager requires username and password to connect.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.