Ok. This while BIT thing is very non-intuitive from my
perspective.
First consider this:
In PSQL:
--------------------------------------
test=# create table foo (bit_val bit(5));
CREATE TABLE
test=# insert into foo (bit_val) values ('B10101');
INSERT 0 1
test=# insert into foo (bit_val) values ('11111');
INSERT 0 1
test=# select * from foo;
bit_val
---------
10101
11111
(2 rows)
------------------------------------
Value 'B11110' IS 100% valid according to
the postgresql manual. (for a BIT(5) column
type).
Now, from JDBC this is impossible.
BOTH of the following give exceptions and
error out.
With val = '11111'
------------------------------------
PreparedStatement pstmt =
con.prepareStatement(
"insert into foo (bit_val) values (?)"
);
pstmt.setString(1, val);
pstmt.executeUpdate();
-----------------------------------
The same with val = 'B11111'
The same with val = true
...etc...
SQLException: SQLState(42804)
Exception in thread "main"
org.postgresql.util.PSQLException: ERROR: column
"bit_val" is of type bit but expression is of type
character varying
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1514)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1299)
-------------------------------------
As far as I can tell, this is a big problem. Or
am I missing something ? [Is there *ANY* way
to get a value into a BIT column from JDBC
via preparedstatements ?]
Best regards,
--j
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com