Thread: Bit string type in PreparedStatement

Bit string type in PreparedStatement

From
bst
Date:
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

Re: Bit string type in PreparedStatement

From
Oliver Jowett
Date:
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

Hi all,

  In my system I alway do a select X from Y.  followed by a  select
count() from Y to get the number of row in my first request.  I heard it
was possible to get the total number of rows from a select in a
VB6/MSSQL env.

Today I saw in PGAdminIII that it gives the count(*) from any query that
return more that 100 lines:  This query return more than 100 rows (12234
rows) do you want to display them.

So did I miss something obvious.  Is it possible to get the total number
of row returned from a query without doing another select.

Thanks to confirm that :-)

Have a goog week-end
/David

Re: Getting the number or row returned by a select. Alway

From
Kris Jurka
Date:

On Fri, 15 Apr 2005, David Gagnon wrote:

> So did I miss something obvious.  Is it possible to get the total number
> of row returned from a query without doing another select.
>

Anytime you've got the results of a query you can loop over it to count
the number of elements.  In JDBC with a scrollable ResultSet you may issue
rs.last() and rs.getRow() to get the number of rows.  rs.beforeFirst()
will then reset the ResultSet back to its original state.

Kris Jurka