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:
-
one You can create the original SQL query, in which
session.createSQLQuery (...). You canuniqueResult (). -
Get a JDBC
get connectiontosession, and the database Remove the connection string from meta-data. For SQL Server, I believe you will need to parseconnection.getMetaData ().)To remove the actual database, please let me know.
Note that session.connection () is considered excluded, and you session.doWork () .
Comments
Post a Comment