JDBC& DB2中的Hiberntate错误:发生了连接授权失败SQL错误:-99999,SQLState:42505

时间:2015-04-08 18:28:32

标签: java hibernate jdbc db2

大家好,我试图在DB2表中更新一行,但是我收到错误

java.sql.SQLException: Connection authorization failure occurred.

在休眠中我有这个:

    StringBuilder sb = new StringBuilder();

    sb.append("UPDATE Scsret set pollife = 'x' ");
    sb.append("WHERE id = 68197");// test dummy update

    Query query = getCurrentSession().createQuery(sb.toString());

    int update = query.executeUpdate();

并收到此错误

WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: -99999, SQLState: 42505
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Connection authorization failure occurred.
org.hibernate.exception.SQLGrammarException: could not prepare statement
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:91)
    at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:90)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:413)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:282)
...
Caused by: java.sql.SQLException: Connection authorization failure occurred.
    at com.ibm.as400.access.JDError.throwSQLException(JDError.java:405)
    at com.ibm.as400.access.AS400JDBCConnection.checkAccess(AS400JDBCConnection.java:388)
    at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1149)
    at com.ibm.as400.access.AS400JDBCPreparedStatement.<init>(AS400JDBCPreparedStatement.java:248)

我也试过使用Pure Jdbc,但我得到了相同的

    StringBuilder sb = new StringBuilder();

    sb.append("UPDATE LSMODDTA.SCSRET SET FEMI  = 20140102 WHERE ID = ");
    sb.append("68196"); //test dummy update

    try {
        PreparedStatement  preparedStatement = conn.prepareStatement(sb.toString());

        int update = preparedStatement.executeUpdate();

        System.out.println(update);



        //System.out.println(update);
    } catch (SQLException e) {
        e.printStackTrace();
    }

并产生此错误

 java.sql.SQLException: Connection authorization failure occurred.
    at com.ibm.as400.access.JDError.throwSQLException(JDError.java:405)
    at com.ibm.as400.access.AS400JDBCConnection.checkAccess(AS400JDBCConnection.java:388)
    at com.ibm.as400.access.AS400JDBCStatement.commonPrepare(AS400JDBCStatement.java:1149)
    at com.ibm.as400.access.AS400JDBCPreparedStatement.<init>(AS400JDBCPreparedStatement.java:248)
    at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:2088)
    at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:1887)

在SQL编辑器中运行生成Hibernate的查询,并且完美地工作

update
        LSMODDTA.SCSRET 
set
        pollife='x' 
where
        id=68196

两个连接都具有相同的用户

发生了什么事?

1 个答案:

答案 0 :(得分:1)

当已建立的连接设置为&#34; readOnly&#34; (详情请见:http://www-01.ibm.com/support/docview.wss?uid=nas8N1016865)。

您可以通过显式设置为FALSE连接的readOnly标志来解决此问题:

connection.setReadOnly(false);