Closed cmdares closed 5 years ago
Hi Crate Team, It seems that jdbc don't support insert NULL value.
CREATE TABLE IF NOT EXISTS log_test (
"id" integer,"log_type" integer,"log_time" long, "server_name" string
)
INSERT INTO log_test ("id","log_type","log_time", "server_name")
VALUES (NULL,NULL,NULL,NULL)
java.sql.BatchUpdateException:
Batch entry 0 INSERT INTO log_test ("id","log_type","log_time", "server_name")
VALUES (NULL,NULL,NULL,NULL) was aborted:
ERROR: Can't map PGType with oid=26 to Crate type
Call getNextException to see other errors in the batch.
It's okay if I use python driver or execute sql in server.
Sorry for the long delay, this somehow slipped through. We cannot reproduce this issue. Following snippet works as expected:
@Test
public void testInsertNull() throws Exception {
try (Connection conn = DriverManager.getConnection("...")) {
Statement stmt1 = conn.createStatement();
stmt1.execute("create table log_test (\n" +
" \"id\" integer,\"log_type\" integer,\"log_time\" long, \"server_name\" string\n" +
")");
PreparedStatement stmt = conn.prepareStatement("insert into log_test (\"id\",\"log_type\",\"log_time\", \"server_name\") values (?, ?, ?, ?)");
stmt.setNull(1, Types.INTEGER);
stmt.setNull(2, Types.INTEGER);
stmt.setNull(3, Types.BIGINT);
stmt.setNull(4, Types.VARCHAR);
stmt.addBatch();
int[] results = stmt.executeBatch();
assertArrayEquals(new int[]{1}, results);
}
}
I'm closing this now. If you still have this issue, please re-open with some reproducible steps including used CrateDB version.
table1(id integer),use jdbc execute batch method to insert data,error!