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
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();
        }
}
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to