{"record":{"id":"d7c59cbe3ab270f8","repo":"pentaho/pentaho-kettle","slug":"unable-to-set-value-on-prepared-statement-on-index-index","errorCode":null,"errorMessage":" : Unable to set value on prepared statement on index \" + index","messagePattern":" : Unable to set value on prepared statement on index \" \\+ index","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaTimestamp.java","lineNumber":537,"sourceCode":"\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException(\n        toStringMeta() + \" : Unable to get timestamp from resultset at index \" + index, e );\n    }\n  }\n\n  @Override\n  public void setPreparedStatementValue( DatabaseMeta databaseMeta, PreparedStatement preparedStatement, int index,\n                                         Object data ) throws KettleDatabaseException {\n\n    try {\n      if ( data != null ) {\n        preparedStatement.setTimestamp( index, getTimestamp( data ) );\n      } else {\n        preparedStatement.setNull( index, java.sql.Types.TIMESTAMP );\n      }\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( toStringMeta() + \" : Unable to set value on prepared statement on index \"\n        + index, e );\n    }\n  }\n\n  @Override\n  public Object convertDataUsingConversionMetaData( Object data2 ) throws KettleValueException {\n    if ( conversionMetadata == null ) {\n      throw new KettleValueException(\n        \"API coding error: please specify the conversion metadata before attempting to convert value \" + name );\n    }\n\n    return super.convertDataUsingConversionMetaData( data2 );\n  }\n\n  @Override\n  public byte[] getBinaryString( Object object ) throws KettleValueException {\n\n    if ( object == null ) {","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaTimestamp.java#L519-L555","documentation":"Thrown by ValueMetaTimestamp.setPreparedStatementValue when binding the timestamp to a JDBC PreparedStatement fails — either setTimestamp() or setNull() throws. Wrapped in a KettleDatabaseException with the field metadata and 1-based? (actually internal) index in the message.","triggerScenarios":"Table output / execute of a prepared statement where the target column rejects the Timestamp (type mismatch, precision overflow, driver rejects java.sql.Types.TIMESTAMP setNull on special columns) or the statement/connection was closed.","commonSituations":"Writing to TIMESTAMP WITH TIME ZONE columns, inserting into columns with narrower precision, stale connections after timeout.","solutions":["Check the chained cause for the driver-level error","Verify target column type accepts java.sql.Timestamp (cast or alter the column)","Reconnect before executing if the connection timed out","Ensure the object being bound is actually a Timestamp, not a Date (use convertData first)"],"exampleFix":"// before\npreparedStatement.setObject(index, new java.util.Date());\n// after\npreparedStatement.setTimestamp(index, new java.sql.Timestamp(date.getTime()));","handlingStrategy":"try-catch","validationCode":"if (!(data instanceof java.sql.Timestamp)) data = tsMeta.convertData(dateMeta, data);\nif (data == null) { /* setNull path is safe */ }","typeGuard":null,"tryCatchPattern":"try {\n  psMeta.setPreparedStatementValue(dbMeta, preparedStatement, index, data);\n} catch (KettleDatabaseException e) {\n  logError(\"Bind failed at index \" + index + \": \" + e.getCause());\n  preparedStatement.setObject(index, data); // driver-generic fallback\n}","preventionTips":["Bind java.sql.Timestamp, not java.util.Date","Confirm target column type/precision accepts the value","Keep connections alive / reconnect on timeout before batch execution","Always test the prepared statement binding in a smoke test against the real DB"],"tags":["pdi","database","jdbc","prepared-statement"],"backgroundTag":"database-write-failed","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"}