Search code examples
javajdbcteradataclob

Teradata CLOB and JDBC : The Locator is invalid because it has been changed ERROR


I'm trying to copy CLOB from one database to another. However I get The Locator is invalid because it has been changed error.

This article says this can happen because ResultSet, PreparedStamenent are closed. However all my objects are open. And the error is thrown when I try to executeBatch()

 Statement select = connectionDB1.createStatement(); 
 ResultSet rs = select.executeQuery("SELECT TOP 1 myClob FROM myTab"); 
 rs.next();  
 PreparedStatement ps = connectionDB2.prepareStatement("INSERT INTO myTab2 SELECT ? ");
 ps.setClob(1, rs.getClob(1)); 
 System.out.println("CLOB inserted");
 ps.addBatch();
 ps.executeBatch(); // ERROR is thrown here before I close any objects WHY? 
                   // java.sql.BatchUpdateException

Why does this happen? How to prevent this?


PS: The above code runs well with any other data type: VARCHAR, DECIMAL


Solution

  • The article says that the CLOB is a locator that is valid in the same session.

    But when you try to apply it to another connection, you are using it in a different session, so the error occurs.

    What you need to do is to read the actual CLOB content from the source database and write it into the target database.