Re: Problems with BIT datatype and preparedStatment - Mailing list pgsql-jdbc

From Ermengol Bota
Subject Re: Problems with BIT datatype and preparedStatment
Date
Msg-id CABX=gB5T4nQ+muNnffWK1oxe4CDFq6Mkc33dVpu8K0TnSXmvnA@mail.gmail.com
Whole thread Raw
In response to Problems with BIT datatype and preparedStatment  (Ermengol Bota <ebota@uoc.edu>)
List pgsql-jdbc
2012/11/26 Thomas Kellerer <spam_eater@gmx.net>
Ermengol Bota, 26.11.2012 14:00:
Hello,

sql.execute("Create Table jdbc_demo (b bit)");
PreparedStatement pstmt = conn.prepareStatement("insert into jdbc_demo values (?)");
pstmt.setBoolean(1,true);  // There is no way to set a value for the bit field  (or I don't know ... :-)
pstmt.execute();

did you try

pstmt.setString(1, "1");
 (I find the boolean type much more "descriptive" anyway for true/false columns)



Yes we did it, and the result is the same

Error Code: 42804
Message: 
ERROR: column "b" is of type bit but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 31

And I agree that boolean is much more better :-)

Actually we solved it using boolean, but I think that may be this could be a bug... I haven't found anyway to set bit (setInt, setString, setObject....), so first of all I ask here if someone knows who's wrong, me or jdbc :-)

Thanks for the answer!
--
* Ermengol *
*************************************************
* Els ordinadors no resolen problemes, *
* simplement executen solucions           *
*************************************************

pgsql-jdbc by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Problems with BIT datatype and preparedStatment
Next
From: dmp
Date:
Subject: Re: Problems with BIT datatype and preparedStatment