How to retrieve connection string url from a Connection object
843859Feb 27 2007 — edited Feb 27 2007I have a piece of code where I receive a Connection object as a parameter. How do get the url of the database ?
String getDatabaseHost(Connection conn) { }
If the connection was created as
conn = DriverManager.getConnection ("jdbc:mysql://localhost/test", "root", "admin");
then
getDatabaseHost(conn) should return the String "jdbc:mysql://localhost/test"
1) Is there any member of Connection that stores the url ?
2) All I am interested is the hostname of the databse. Is there any DBMS-indepedent query that returns the hostname ?