java - How can I get the database name I am connected to through Hibernate? -


I am trying to get the database name associated with SQL Server. I tried to do this:

  query query = session .createQuery ("SELECT db_name ()"); & Lt; String & gt; DbNames = query.list ();  

However, I found the following error:

  [Error Parasar: 35] *** Error: & lt; AST>: 0: 0: The end of the unexpected subtitle "main" java.lang.IllegalStateException in the thread: There is no data type for the node: org.hibernate.hql.ast.MethodNode \ - [METHOD_CALL] Method node: '(* - [METHOD_NAME] IdentNode:' db_name '{originalText = db_name} \ - [EXPR_LIST] SQLNode:' Xpillist ' 

How to get the name of the database I am associated with

You either:

  1. one You can create the original SQL query, in which session.createSQLQuery (...) . You can uniqueResult () .

  2. Get a JDBC get connection to session , and the database Remove the connection string from meta-data. For SQL Server, I believe you will need to parse connection.getMetaData ().) To remove the actual database, please let me know.

Note that session.connection () is considered excluded, and you session.doWork () .


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -