Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to retrieve connection string url from a Connection object

843859Feb 27 2007 — edited Feb 27 2007
I 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 ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2007
Added on Feb 27 2007
2 comments
132 views