English 中文(简体)
PSQL 不抓获的例外
原标题:PSQLException not getting caught

我使用Tomcat 6和Postgresql 8.4. 我的代码如下:

try {
  // Prepared statement inserting something...
} catch (final PSQLException e) {
  LOG.log(Level.SEVERE, "Saving failed.", e);
} catch (final SQLException e) {
  LOG.log(Level.SEVERE, "Saving failed (SQL).", e);
}

在 DB 中插入此选项可能导致 PSQL 例外( 例如, 一种独特的密钥违规), 我想用第一个 < code > captain 来捕捉该例外 。 然而, 我在日志中实际找到的是 :

SEVERE: Saving failed (SQL).
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "UZIVATELIA_U_LOGIN"
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at cz.ecoremedia.realpad.web.backend.Users.saveNewUser(Users.java:119)
    at cz.ecoremedia.realpad.web.backend.Users.saveUser(Users.java:237)
    at org.apache.jsp.User_jsp._jspService(User_jsp.java:159)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)

如果我检查我抓到的 e 类型, 例如 :

} catch (final SQLException e) {
  LOG.log(Level.SEVERE, e.getClass().getName());
  LOG.log(Level.SEVERE, "Saving failed (SQL).", e);

它仍然告诉我它是org.postagresql.util.PSQLExpendion

当我在本地的日志中尝试这个时, 它非常有效 - PSQLExpendion 被正确捕获到第一个 抓获点 块 。

如果我正确理解问题, 我所抓的 org. postgresql. util. PSQLExpeption 与实际被丢弃的 org. mostgresql. util. PSQLExpendion 不同。 这怎么可能? 我在做什么错?

谢谢你的点子

最佳回答

结果发现,除了WEB-INF/lib/ 中的驱动程序外,我还有另一个JDBC驱动程序在我的Tomcat s lib/ 文件夹中。

@NathanHughes. 感谢。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签