From fc1476a8b1e654482f48f9f6d416dd67722e762d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20N=C3=B8kleby?= Date: Thu, 20 Feb 2025 21:12:59 +0100 Subject: [PATCH] Remove null bytes from strings before insertion on postgreql. Ref : https://stackoverflow.com/questions/1347646/postgres-error-on-insert-error-invalid-byte-sequence-for-encoding-utf8-0x0 --- .../postgresql/out/PostgreSQLJDBCExportModule.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dbptk-modules/dbptk-module-postgresql/src/main/java/com/databasepreservation/modules/postgresql/out/PostgreSQLJDBCExportModule.java b/dbptk-modules/dbptk-module-postgresql/src/main/java/com/databasepreservation/modules/postgresql/out/PostgreSQLJDBCExportModule.java index a70c8e31..329593f7 100644 --- a/dbptk-modules/dbptk-module-postgresql/src/main/java/com/databasepreservation/modules/postgresql/out/PostgreSQLJDBCExportModule.java +++ b/dbptk-modules/dbptk-module-postgresql/src/main/java/com/databasepreservation/modules/postgresql/out/PostgreSQLJDBCExportModule.java @@ -310,4 +310,15 @@ public String apply(Cell cell) { ps.setArray(index, sqlArray); } + +@Override +protected void handleSimpleTypeStringDataCell(String data, PreparedStatement ps, int index, Cell cell, + ColumnStructure column) throws SQLException { + if (data != null) { + data = data.replace("\u0000", ""); + ps.setString(index, data); + } else { + ps.setNull(index, Types.VARCHAR); + } + } }