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();
        }
        }
Raghav
  • 1
  • 4
  • Hope this link helps http://stackoverflow.com/questions/17208937/mysql-connection-with-out-password-using-corejava-program-getting-access-denied – Shriram Nov 29 '15 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. – try-catch-finally Nov 29 '15 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. – Markus W Mahlberg Nov 29 '15 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 – Raghav Nov 30 '15 at 03:37

1 Answers1

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.

Murat
  • 72
  • 10