postgres jdbc 8.3和jdbc 8.4版本之间Exception.getMessage()不同的原因



我通过Java Exception捕获了postgres的异常,但是它在postgres jdbc 8.3和8.4驱动程序中带来了不同类型的消息…

当我在8.3 jdbc驱动程序中使用Exception.getMessage()时,它会带来

ERROR: "my pgsql raise exception"

当我在8.4 jdbc驱动程序中使用Exception.getMessage()时,它会带来

ERROR: "my pgsql raise exception"

Where: SQL语句"发生错误的语句"

如何避免"Where:"子句而不分裂字符串??

这是我的代码:

   try {
      ...
   } catch (Exception e) {
       System.out.println(e.getMessage());
   }

如果您需要错误的特定子字段,请使用提供的API。

try {
   ...
} catch (org.postgresql.util.PSQLException e) {
    System.out.println(e.getServerErrorMessage().getMessage());
} catch (Exception e) {
    System.out.println(e.getMessage());
}

如果您想做比简单的捕获更复杂的事情,Apache ExceptionUtils可以很方便。

最新更新