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

前端 未结 4 1248
无人共我
无人共我 2020-12-08 12:54

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 Co

相关标签:
4条回答
  • 2020-12-08 13:27

    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();
    
    0 讨论(0)
  • 2020-12-08 13:27

    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.

    0 讨论(0)
  • 2020-12-08 13:38

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

    0 讨论(0)
  • 2020-12-08 13:47

    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

    0 讨论(0)
提交回复
热议问题