How to get database url from java.sql.Connection?

Rasto picture Rasto · Apr 19, 2011 · Viewed 62.1k times · Source

For given Connection instance how do I find out url that the Connection uses to connect the database ? Is it somewhere in Properties returned by Connection.getClientInfo() method?

If there you need me to provide clearer description all comments are welcome. Thank you

Answer

Ken Chan picture Ken Chan · Apr 19, 2011

Connection has the getMetaData() to return DatabaseMetaData . DatabaseMetaData has the getURL() to return the URL for this DBMS.