【问题标题】:why Exception.getMessage() differs between postgres jdbc 8.3 and jdbc 8.4 versions? [closed]为什么 Exception.getMessage() 在 postgres jdbc 8.3 和 jdbc 8.4 版本之间有所不同? [关闭]
【发布时间】:2014-05-19 21:52:23
【问题描述】:

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

当我将 Exception.getMessage() 与 8.3 jdbc 驱动程序一起使用时,它会带来

错误:“我的 pgsql 引发异常”

当我将 Exception.getMessage() 与 8.4 jdbc 驱动程序一起使用时,它会带来

错误:“我的 pgsql 引发异常”

Where:SQL语句“发生错误的语句”

如何在不拆分字符串的情况下避免“Where:”子句??

这是我的代码:

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

【问题讨论】:

  • 没有什么要求 PostGRES 在版本之间保持错误消息不变。也很难相信 PostGRES 真的提供了这样的文盲信息。

标签: java postgresql exception jdbc


【解决方案1】:

如果您想要错误的特定子字段,use the API provided

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 2021-03-29
    • 2018-07-27
    相关资源
    最近更新 更多