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

Lists: pgsql-jdbc
From: bst <bst_co(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Bit string type in PreparedStatement
Date: 2005-04-14 15:45:07
Message-ID: 20050414154508.66799.qmail@web50407.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: bst <bst_co(at)yahoo(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Bit string type in PreparedStatement
Date: 2005-04-14 21:32:52
Message-ID: 425EE184.8060303@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: David Gagnon <dgagnon(at)siunik(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Getting the number or row returned by a select. Alway tought it was not possible until I say pgAdmin who gives it
Date: 2005-04-15 19:53:33
Message-ID: 42601BBD.6060307@siunik.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

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


From: Kris Jurka <books(at)ejurka(dot)com>
To: David Gagnon <dgagnon(at)siunik(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Getting the number or row returned by a select. Alway
Date: 2005-04-15 20:04:06
Message-ID: Pine.BSO.4.56.0504151459290.21687@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

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