Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 783
Rasto Avatar asked Apr 19 '11 15:04

Rasto


People also ask

How do I find my JDBC database URL?

The DatabaseMetaData#getURL Method In the above example, we first obtain the Connection instance. Then, we call the getMetaData method on our Connection to get the DatabaseMetaData. Finally, we call the getURL method on the DatabaseMetaData instance. As we'd expect, it returns the URL of our database.

What is database URL in Java?

A database connection URL is a string that your DBMS JDBC driver uses to connect to a database. It can contain information such as where to search for the database, the name of the database to connect to, and configuration properties.


1 Answers

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

like image 198
Ken Chan Avatar answered Sep 22 '22 10:09

Ken Chan