Thread: BIT vs boolean
According to the jdbc doc's one should set a BIT value in a prepared statement using the setBoolean function. So I think the following should work: stat = con.createStatement(); stat.execute( "CREATE TABLE bitTable( b BIT )" ); pstat = con.prepareStatement( "INSERT INTO bitTable( b ) VALUES( ? )" ); pstat.setBoolean( 1, true ); pstat.execute(); However with pgsql-jdbc 7.3.3 build 110, I get the following error: Exception in thread "main" java.sql.SQLException: ERROR: Cannot parse 't' as a binary digit at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131) at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.jav a:505) at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java: 320) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java: 48) at SQLBug.main(SQLBug.java:34) Is setBoolean is just printing true or false into a string and expecting the database side to parse it? Maybe it should check the type of the column to determine if the boolean value should be printed as true/false or 0/1 (or whatever BIT is expecting to see). Darin
I think there is a patch posted for this already. Kim can confirm if that is so. Fernando Darin Ohashi wrote: > According to the jdbc doc's one should set a BIT value in a prepared statement > using the setBoolean function. So I think the following should work: > > stat = con.createStatement(); > > stat.execute( "CREATE TABLE bitTable( b BIT )" ); > > pstat = con.prepareStatement( "INSERT INTO bitTable( b ) VALUES( ? )" ); > > pstat.setBoolean( 1, true ); > > pstat.execute(); > > However with pgsql-jdbc 7.3.3 build 110, I get the following error: > > Exception in thread "main" java.sql.SQLException: ERROR: Cannot parse 't' as a > binary digit > > at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131) > at > org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.jav > a:505) > at > org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java: > 320) > at > org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java: > 48) > at SQLBug.main(SQLBug.java:34) > > Is setBoolean is just printing true or false into a string and expecting the > database side to parse it? Maybe it should check the type of the column to > determine if the boolean value should be printed as true/false or 0/1 (or > whatever BIT is expecting to see). > > Darin > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match > -- Fernando Nasser Red Hat Canada Ltd. E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9
On Fri, 2003-06-27 at 16:33, Fernando Nasser wrote: > I think there is a patch posted for this already. > Kim can confirm if that is so. > I don't have one for it, but I could whip one up fairly quickly. I was going to do it for my patch, but I got sidetracked apparently. I remember looking at it though. The reason why it doesn't work is: It is actually insert into bittable values (b'1'); instead of insert into bittable values (true); Will look at it either later tonight or tomorrow. Cheers, Kim