pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bit string type in PreparedStatement
2+ messages / 2 participants
[nested] [flat]

* Bit string type in PreparedStatement
@ 2005-04-14 15:45  bst <bst_co@yahoo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: bst @ 2005-04-14 15:45 UTC (permalink / raw)
  To: pgsql-jdbc

I have a table with a bit string field
CREATE TABLE test (a BIT(8));
 
When I get the type of this filed from Java
 
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT a FROM
test");
ResultSetMetaData rsmd = rs.getMetaData();
int type = rsmd.getColumnType(1);
String name = rsmd.getColumnTypeName(1);
 
I get
 
type=-7 that is equal to java.sql.Types.BIT
name=bit
 
 
Now I'd like to set the field in a PreparedStatement
PreparedStatement update =
connection.prepareStatement("UPDATE test SET a=?");
update.setObject(1, "B10101010", java.sql.Types.BIT);
update.executeUpdate();
 
and I get
org.postgresql.util.PSQLException: ERROR: column "a"
is of type bit but expression is of type boolean
 
How can I set bit string field in PreparedStatement?
 
 
Thanks.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Bit string type in PreparedStatement
@ 2005-04-14 21:32  Oliver Jowett <oliver@opencloud.com>
  parent: bst <bst_co@yahoo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Oliver Jowett @ 2005-04-14 21:32 UTC (permalink / raw)
  To: bst <bst_co@yahoo.com>; +Cc: pgsql-jdbc

bst wrote:

> CREATE TABLE test (a BIT(8));

> How can I set bit string field in PreparedStatement?

As far as I can tell, there's no standard way to do this; the JDBC spec
thinks BIT is just like BOOLEAN.

You could use setString() and an explicit cast to bit(8) in your query,
perhaps..

-O



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-04-14 21:32 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 15:45 Bit string type in PreparedStatement bst <bst_co@yahoo.com>
2005-04-14 21:32 ` Oliver Jowett <oliver@opencloud.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox