Hibernate异常,PSQLException,打印消息

时间:2018-10-10 13:26:41

标签: exception-handling hibernateexception extract-error-message

我的Eclipse控制台中有这样的PSQLException:

Oct 10, 2018 7:52:22 PM org.postgresql.Driver connect
SEVERE: Connection error: 
org.postgresql.util.PSQLException: FATAL: database "xyz" does not exist
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2477)
    ...

我想打印错误消息以通知用户有关错误,我该怎么做?

这是我的代码:

private static SessionFactory buildSessionFactory() {
    try {
        //code here
    } catch (HibernateException he) {
        //print to JDialog (skip code)
        he.getMessage(); --> result : Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvirontment]
        he.getCause().getMessage(); --> result : Error Calling Driver #connect   
    }

我如何打印FATAL:数据库“ xyz”不存在?

非常感谢...

0 个答案:

没有答案