Getting an exception ORA-00942: table or view does not exist - when inserting into an existing table

前端 未结 10 1338
[愿得一人]
[愿得一人] 2020-11-28 15:17

I am getting below exception, when trying to insert a batch of rows to an existing table

ORA-00942: table or view does not exist

<
相关标签:
10条回答
  • 2020-11-28 15:30

    Here I got the solution for the question. The problem is on glass fish if you are using it. When you create JNDI name make sure pool name is correct and pool name is the name of connection pool name that you are created.

    enter image description here

    0 讨论(0)
  • 2020-11-28 15:37

    I found how to solve this problem without using JDBC's setString() method which limits the data to 4K.

    What you need to do is to use preparedStatement.setClob(int parameterIndex, Reader reader). At least this is what that worked for me. Thought Oracle drivers converts data to character stream to insert, seems like not. Or something specific causing an error.

    Using a characterStream seems to work for me. I am reading tables from one db and writing to another one using jdbc. And i was getting table not found error just like it is mentioned above. So this is how i solved the problem:

    case Types.CLOB:   //Using a switch statement for all columns, this is for CLOB columns
            Clob clobData = resultSet.getClob(columnIndex); // The source db
            if (clobData != null) {
                preparedStatement.setClob(columnIndex, clobData.getCharacterStream());
            } else {
                preparedStatement.setClob(columnIndex, clobData);
            }
            clobData = null;
            return;
    

    All good now.

    0 讨论(0)
  • 2020-11-28 15:42

    There seems to be some issue with setCLOB() that causes an ORA-00942 under some circumstances when the target table does exist and is correctly privileged. I'm having this exact issue now, I can make the ORA-00942 go away by simply not binding the CLOB into the same table.

    I've tried setClob() with a java.sql.Clob and setCLOB() with an oracle.jdbc.CLOB but with the same result.

    As you say, if you bind as a string the problem goes away - but this then limits your data size to 4k.

    From testing it seems to be triggered when a transaction is open on the session prior to binding the CLOB. I'll feed back when I've solved this...checking Oracle support.

    0 讨论(0)
  • 2020-11-28 15:43

    It works for me:

    Clob clob1;
    while (rs.next()) {
       rs.setString(1, rs.getString("FIELD_1"));
    
       clob1 = rs.getClob("CLOB1");
       if (clob1 != null) {
          sta.setClob(2, clob1.getCharacterStream());
       } else {
          sta.setClob(2, clob1);
       }
       clob1 = null;
    
       sta.setString(3, rs.getString("FIELD_3"));
    }
    
    0 讨论(0)
  • 2020-11-28 15:43

    Is it possible that you are doing INSERT for VARCHAR but doing an INSERT then an UPDATE for CLOB?

    If so, you'll need to grant UPDATE permissions to the table in addition to INSERT.

    See https://stackoverflow.com/a/64352414/1089967

    0 讨论(0)
  • 2020-11-28 15:44

    Oracle will also report this error if the table exists, but you don't have any privileges on it. So if you are sure that the table is there, check the grants.

    0 讨论(0)
提交回复
热议问题