postgresql – PSQLException:当前事务被中止,命令被忽略,直到
我看到以下(截断)堆栈跟踪在JBoss 7.1.1的server.log文件Final:
Caused by: org.postgresql.util.PSQLException: ERROR: current transaction is aborted,commands ignored until end of transaction block 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:512) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:302) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_23] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_23] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_23] at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_23] at org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.invoke(AbstractJdbc23PooledConnection.java:455) at $Proxy49.executeUpdate(Unknown Source) at org.jboss.jca.adapters.jdbc.WrappedStatement.executeUpdate(WrappedStatement.java:371) at org.infinispan.loaders.jdbc.TableManipulation.executeUpdateSql(TableManipulation.java:154) [infinispan-cachestore-jdbc-5.1.2.FINAL.jar:5.1.2.FINAL] ... 154 more 检查Postgres日志文件显示以下语句: STATEMENT: SELECT count(*) FROM ISPN_MIXED_BINARY_TABLE_configCache ERROR: current transaction is aborted,commands ignored until end of transaction block STATEMENT: CREATE TABLE ISPN_MIXED_BINARY_TABLE_configCache(ID_COLUMN VARCHAR(255) NOT NULL,DATA_COLUMN BYTEA,TIMESTAMP_COLUMN BIGINT,PRIMARY KEY (ID_COLUMN)) ERROR: relation "ispn_mixed_binary_table_configcache" does not exist at character 22 我使用JBoss 7.1.1 Final附带的Infinispan,它是5.1.2.Final。 所以这是我认为发生: > Infinispan尝试运行SELECT count(*)…语句以查看ISPN_MIXED_BINARY_TABLE_configCache中是否有任何记录; 这个错误是什么意思和任何想法如何解决它?
我得到这个错误使用Java和postgresql在表上执行插入。我将说明如何重现这个错误:
org.postgresql.util.PSQLException: ERROR: current transaction is aborted,commands ignored until end of transaction block 概要: 得到此错误的原因是因为您输入了一个事务,并且您的一个SQL查询失败,并且您忽略了该失败并忽略它。但这还不够,所以你使用同样的连接,使用SAME TRANSACTION来运行另一个查询。第二个正确形成的查询会抛出异常,因为您正在使用损坏的事务来执行其他工作。 PostgreSQL默认阻止你这样做。 我使用:PostgreSQL 9.1.6 on x86_64-redhat-linux-gnu,由gcc(GCC)编译4.7.2 20120921(Red Hat 4.7.2-2),64位“。 我的postgresql驱动是:postgresql-9.2-1000.jdbc4.jar 使用java版本:Java 1.7 这里是表的create语句来说明异常: CREATE TABLE moobar ( myval INT ); Java程序导致错误: public void postgresql_insert() { try { connection.setAutoCommit(false); //start of transaction. Statement statement = connection.createStatement(); System.out.println("start doing statement.execute"); statement.execute( "insert into moobar values(" + "'this sql statement fails,and it " + "is gobbled up by the catch,okfine'); "); //The above line throws an exception because we try to cram //A string into an Int. I Expect this,what happens is we gobble //the Exception and ignore it like nothing is wrong. //But remember,we are in a TRANSACTION! so keep reading. System.out.println("statement.execute done"); statement.close(); } catch (SQLException sqle) { System.out.println("keep on truckin,keep using " + "the last connection because what could go wrong?"); } try{ Statement statement = connection.createStatement(); statement.executeQuery("select * from moobar"); //This SQL is correctly formed,yet it throws the //'transaction is aborted' SQL Exception,why? Because: //A. you were in a transaction. //B. You ran a sql statement that failed. //C. You didn't do a rollback or commit on the affected connection. } catch (SQLException sqle) { sqle.printStackTrace(); } } 上面的代码为我生成这个输出: start doing statement.execute keep on truckin,keep using the last connection because what could go wrong? org.postgresql.util.PSQLException: ERROR: current transaction is aborted,commands ignored until end of transaction block 解决方法: 您有几个选项: >最简单的解决方案:不要在事务中。设置connection.setAutoCommit(false);到connection.setAutoCommit(true);.它工作原因,因为失败的SQL只是被忽略作为失败的sql语句。你欢迎失败sql语句所有你想要和postgresql不会阻止你。 在保护postgresql的决定做这样的事情…甲骨文让你软中间让你做蠢的东西,俯瞰它。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |