If the preparedStatement sql is fixed, how can I do the insert?
create table if not exists ttqs_a (b bit(1));
try(PreparedStatement ps = conn.prepareStatement("insert into ttqs_a values(?)")){
ps.setObject(1,1, Types.BIT);
ps.execute();
}
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: column "b" is of type bit but expression is of type boolean
I don't think you can tell the JDBC driver to use the data type bit
on the database side, you you will have to add a type cast:
INSERT INTO ttqs_a VALUES (CAST(? AS bit))
Then use any of the types that can be cast to bit
, such as text
stmt.setString(1, "0");
or integer
stmt.setInt(1, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With