{"record":{"id":"8e70daff5dd29a23","repo":"pentaho/pentaho-kettle","slug":"unable-to-set-internet-address-value-on-prepared-statement","errorCode":null,"errorMessage":" : Unable to set Internet address value on prepared statement on index \" + index","messagePattern":" : Unable to set Internet address 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/ValueMetaInternetAddress.java","lineNumber":528,"sourceCode":"      return convertStringToInternetAddress( resultSet.getString( index + 1 ) );\n\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( toStringMeta()\n        + \" : Unable to get Internet Address from resultset at index \" + index, e );\n    }\n\n  }\n\n  @Override\n  public void setPreparedStatementValue( DatabaseMeta databaseMeta, PreparedStatement preparedStatement,\n    int index, Object data ) throws KettleDatabaseException {\n\n    try {\n\n      preparedStatement.setObject( index, getString( data ), Types.OTHER );\n\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( toStringMeta()\n        + \" : Unable to set Internet address value on prepared statement on index \" + index, e );\n    }\n\n  }\n\n  @Override\n  public String getDatabaseColumnTypeDefinition( DatabaseInterface databaseInterface, String tk, String pk,\n    boolean use_autoinc, boolean add_fieldname, boolean add_cr ) {\n\n    String retval = null;\n    if ( databaseInterface instanceof PostgreSQLDatabaseMeta ) {\n      if ( add_fieldname ) {\n        retval = getName() + \" \";\n      } else {\n        retval = \"\";\n      }\n      retval += \"INET\";\n      if ( add_cr ) {","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaInternetAddress.java#L510-L546","documentation":"setPreparedStatementValue() binds the address by converting it to its String form and calling setObject(index, value, Types.OTHER). Any failure — driver rejection of Types.OTHER, closed statement, type incompatibility — is wrapped in KettleDatabaseException 'Unable to set Internet address value on prepared statement on index N'.","triggerScenarios":"Executing inserts/updates through a prepared statement where the target column type or JDBC driver does not accept a String bound with Types.OTHER (e.g., drivers lacking inet type mapping), or the statement is invalid/closed.","commonSituations":"Writing IP values into PostgreSQL 'inet' columns with drivers expecting typed parameters; databases with no inet datatype (MySQL, Oracle) rejecting Types.OTHER; prepared statement reused after connection failure.","solutions":["Cast the value in the SQL itself (e.g., '?::inet' on PostgreSQL) or use a String-typed field and let the DB cast","Change the target column to VARCHAR and store the textual address","Verify the JDBC driver version supports setObject with Types.OTHER for the column type","Catch KettleDatabaseException and check connection/statement state before retrying"],"exampleFix":"// before\n\"INSERT INTO hosts(ip) VALUES (?)\" // bound with Types.OTHER\n// after\n\"INSERT INTO hosts(ip) VALUES (CAST(? AS inet))\" // or store into a varchar column","handlingStrategy":"try-catch","validationCode":"// verify driver accepts Types.OTHER for the column\nDatabaseMetaData dmd = conn.getMetaData();\nboolean ok = dmd != null; // plus test setObject once per connection","typeGuard":null,"tryCatchPattern":"try { ps.setObject(idx, val, Types.OTHER); } catch (SQLException e) { ps.setObject(idx, val, Types.VARCHAR); }","preventionTips":["Cast in SQL ('?::inet') instead of relying on Types.OTHER","Store addresses as VARCHAR when the DB lacks an inet type","Use a recent JDBC driver","Check connection health before batch writes"],"tags":["database","jdbc","prepared-statement","inetaddress","kettle"],"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"}