{"record":{"id":"b7e943b758169a75","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-inserting-updating-row-in-part","errorCode":null,"errorMessage":"Unexpected error inserting/updating row in part [","messagePattern":"Unexpected error inserting/updating row in part \\[","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":1623,"sourceCode":"        } else {\n          debug = \"insertRow normal commit\";\n          commit();\n        }\n        written = 0;\n        rowsAreSafe = true;\n      }\n\n      return rowsAreSafe;\n    } catch ( BatchUpdateException ex ) {\n      throw createKettleDatabaseBatchException( \"Error updating batch\", ex );\n    } catch ( SQLException ex ) {\n      if ( isBatchUpdate ) {\n        throw createKettleDatabaseBatchException( \"Error updating batch\", ex );\n      } else {\n        throw new KettleDatabaseException( \"Error inserting/updating row\", ex );\n      }\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"Unexpected error inserting/updating row in part [\" + debug + \"]\", e );\n    }\n  }\n\n  /**\n   * Clears batch of insert prepared statement\n   *\n   * @throws KettleDatabaseException\n   * @deprecated\n   */\n  @Deprecated\n  public void clearInsertBatch() throws KettleDatabaseException {\n    clearBatch( prepStatementInsert );\n  }\n\n  public void clearBatch( PreparedStatement preparedStatement ) throws KettleDatabaseException {\n    try {\n      preparedStatement.clearBatch();\n    } catch ( SQLException e ) {","sourceCodeStart":1605,"sourceCodeEnd":1641,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L1605-L1641","documentation":"Caught when the same execution path throws a non-SQLException Exception (not SQLException, not BatchUpdateException): wrapped as 'Unexpected error inserting/updating row in part [' + debug + ']'. The debug string names which internal statement part was executing. Since JDBC normally throws SQLException, this usually indicates an infrastructure/runtime problem rather than a SQL error.","triggerScenarios":"Any RuntimeException/Error escaping during executeUpdate — e.g. NullPointerException from unset internal state (null prepared statement), ClassCastException in driver code, KettleRuntimeException, or OutOfMemoryError building large batch payloads.","commonSituations":"Calling insertRow/executeAndClearBatch before the prepared statement was created; heap exhaustion with very large batches; driver bugs throwing runtime exceptions; concurrent use of a Database object from two threads.","solutions":["Read the cause stack trace — this is 'unexpected', so the cause is the real story","Ensure the insert prepared statement was created (setInsertBatch/prepareInsert) before executing rows","Do not share one Database instance across threads without synchronization","Reduce batch size to rule out memory pressure","Check the 'part [' + debug + ']' label to locate the failing statement part"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (database.getConnection() == null || database.getConnection().isClosed()) {\n  throw new IllegalStateException(\"Cannot insert: connection not open\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  database.insertRow(tableName, rowMeta, data);\n} catch (KettleDatabaseException e) {\n  Throwable c = e.getCause();\n  if (c instanceof RuntimeException || c instanceof Error) {\n    throw new IllegalStateException(\"Infrastructure failure in part \" + e.getMessage(), c);\n  }\n  throw e;\n}","preventionTips":["Always prepareInsert before inserting rows","Use one Database instance per thread","Bound batch sizes to avoid heap exhaustion","Pin/verify JDBC driver versions"],"tags":["jdbc","runtime-exception","insert-update"],"backgroundTag":"internal-invariant-violation","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}