pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Johann Robette <jrobette@onyme.com>
Cc: pgsql-general@postgresql.org
Cc: PostGreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: [JDBC] Problem with boolean type
Date: Thu, 7 Oct 2004 10:19:18 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0410071017190.14222@leary.csoft.net> (raw)
In-Reply-To: <002401c4ac7c$9e6c33f0$a5010a0a@Johann>
References: <002401c4ac7c$9e6c33f0$a5010a0a@Johann>



On Thu, 7 Oct 2004, Johann Robette wrote:

> I use EJB to create a record in a table containing a Boolean field
> "answered".
> The EJB method expects a Boolean object so I pass new Boolean(false) in
> order to create it as false.
> 
> But I get the following error : 
> java.sql.SQLException: ERROR: column "answered" is of type boolean but
> expression is of type text

I don't see how that could be happening.  The attached test works fine for 
me and exercises every way I see to set a boolean.  Perhaps the EJB is 
internally converting this to a setString() call?  Could you investigate 
more into what actual driver calls are being made?

Kris Jurka

Attachments:

BoolTest.java (text/plain, 990B) download import java.sql.*; public class BoolTest { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5750/jurka","jurka",""); Statement stmt = conn.createStatement(); stmt.execute("CREATE TEMP TABLE tt (ans bool)"); stmt.close(); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tt (ans) VALUES (?)"); pstmt.setObject(1, new Boolean(false)); pstmt.executeUpdate(); pstmt.setBoolean(1, false); pstmt.executeUpdate(); pstmt.setObject(1, new Boolean(false), Types.BIT); pstmt.executeUpdate(); pstmt.setObject(1, new Boolean(false), Types.BOOLEAN); pstmt.executeUpdate(); pstmt.close(); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT ans FROM tt"); while (rs.next()) { System.out.println(rs.getBoolean(1)); } rs.close(); stmt.close(); conn.close(); } }

view thread (3+ messages)  latest in thread

Message-ID: <Pine.BSO.4.56.0410071017190.14222@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0410071017190.14222@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0410071017190.14222@leary.csoft.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, jrobette@onyme.com, pgsql-general@postgresql.org
  Subject: Re: [JDBC] Problem with boolean type
  In-Reply-To: <Pine.BSO.4.56.0410071017190.14222@leary.csoft.net>
  References: <002401c4ac7c$9e6c33f0$a5010a0a@Johann> <Pine.BSO.4.56.0410071017190.14222@leary.csoft.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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