Get the name of the databases stored in a DBMS

0

I am trying to make a connection to a database manager (postgresql, Mysql and Access) and I would like to know if there is any way to connect to the manager and extract the information from the name of the databases that are stored there. All this using JAVA. I need to obtain the name of the databases stored in the 3 managers not at the same time but using different functions, methods or classes. I'm following the standard procedure of connecting to a database, but I do not want to connect to a specific one but I want to get the name of all of them.

String stringConnection = "jdbc:postgresql://" + this.host + ":" + this.port + "/" + this.database; 

Class.forName("org.postgresql.Driver").newInstance(); 

conn = DriverManager.getConnection(stringConnection, this.user, this.password);

 //Son las principales líneas de conexión que estoy empleando.
    
asked by Anangela Jugo 22.07.2018 в 03:59
source

1 answer

0

You should have 3 methods, one for each connection. In each method you already put the URL of the 'JDBC and in that URL is the name of the database, and if you want the name then what you should do is the following.

String url = "jdbc:mysql://localhost:3306/pedidos?zeroDateTimeBehavior=convertToNull"
//Como vez ahí esta mi bd pedidos
Connection conn = DriverManager.getConnection(url, "usuario", "pass");
String name = conn.getMetaData().getUrl();
//Obtienes lo mismo que la url, debes de ver como parsear esa url para obtener el nombre.
    
answered by 22.07.2018 в 07:43