How to get the default schema of a SQL connection?

后端 未结 1 1571
野性不改
野性不改 2021-01-26 03:56

From within a java code - where I already have a connection to a database - I need to find the default schema of the connection.

I have the following code that gives me

相关标签:
1条回答
  • 2021-01-26 04:46

    Please use connection.getMetaData().getURL() method which returns String like

    jdbc:mysql://localhost:3306/?autoReconnect=true&useUnicode=true&characterEncoding=utf8
    

    We can parse it easily and get the schema name. It works for all JDBC drivers.

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