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

耗尽温柔 提交于 2019-11-28 06:08:51

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

Lucas de Oliveira

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();
Mehdi

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

connection.getClientInfo() has all the details related to connection. It returns a properties object. You can retrieve the value of "password" property to fetch the password that was used for the connection object.

Please let me know if this solves your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!