How to get database url from java.sql.Connection?
Solution 1:
Connection
has the getMetaData()
to return DatabaseMetaData
. DatabaseMetaData
has the getURL()
to return the URL for this DBMS.
Solution 2:
I believe you can use the DatabaseMetaData object from the Connection and then get the URL. Try:
DatabaseMetaData dmd = connection.getMetaData();
String url = dmd.getURL();
Solution 3:
Inside the Connection object, you have an object of type DatabaseMetaData, it contains a lot of information about the database.
Lucas de Oliveira gave you a good example of code.
And here is the documentation of the object : Interface DatabaseMetaData