java - DB2 中的 JDBC 和 Hibernate 错误 : Connection authorization failure occurred | SQL Error: -99999, SQLState: 42505

标签 java hibernate jdbc db2

大家好,我尝试更新 DB2 表中的一行,但出现错误

java.sql.SQLException: Connection authorization failure occurred.

在 hibernate 状态下我有这个:

    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

两个连接具有相同的用户

发生什么事了?

最佳答案

当已建立的连接设置为“readOnly”时,可能会导致此问题(了解更多信息:http://www-01.ibm.com/support/docview.wss?uid=nas8N1016865)。

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

connection.setReadOnly(false);

关于java - DB2 中的 JDBC 和 Hibernate 错误 : Connection authorization failure occurred | SQL Error: -99999, SQLState: 42505,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29522564/

相关文章:

java - org.dbunit.dataset.NoSuchTableException : Did not find table 'xxx' in schema 'null'

java - 如何检测 GWT 元素是否可见?

hibernate - 在 Hibernate 中为 DB2 和 HSQLDB 映射名为 "group"的表

java - JDBC ResultSet 获取具有表别名的列

java - 如何为查询创建一个标志,以便如果添加记录,则显示 "successful",如果没有,则显示 "unsuccessful"

java - JFrame 显示不正确

java - LWJGL 顶点和片段着色器无法编译(错误 CO206)

java - Java有堆和栈吗?

java - hibernate.异常.SQLGrammarException : could not extract ResultSet: ORA-00942: table or view does not exist

java - hibernate 和日期类型 : length attribute