pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Dudziak <tomdzk@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Exception when inserting boolean values into BIT columns
Date: Mon, 20 Jun 2005 12:05:35 +0200
Message-ID: <224f3234050620030565ffa711@mail.gmail.com> (raw)

I have a problem with BIT datatypes accessed via JDBC. When I try to
insert a Boolean value via a PreparedStatement, I get the following
exception (using the newest JDBC driver, postgresql-8.0-311.jdbc3.jar,
against a 8.0.1 database on Windows, Java is 1.5.0_1):

Exception in thread "main" java.sql.SQLException: ERROR: column "isok"
is of type bit but expression is of type boolean
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1471)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1256)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:175)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:389)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:330)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:321)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:168)
	at Main.main(Main.java:27)


This is the corresponding test code:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.Types;
import org.apache.commons.dbcp.BasicDataSource;

public class Main
{
    public static void main(String[] args) throws Exception
    {
        BasicDataSource dataSource = new BasicDataSource();

        dataSource.setDriverClassName("org.postgresql.Driver");
        dataSource.setUrl("jdbc:postgresql://localhost/test");
        dataSource.setUsername("postgres");
        dataSource.setPassword("root123");

        Connection connection = dataSource.getConnection();
        Statement  statement  = connection.createStatement();

        statement.execute("CREATE TABLE Test(id SERIAL, isOk BIT);");
        statement.close();

        PreparedStatement prepStatement =
connection.prepareStatement("INSERT INTO Test (isOk) VALUES (?);");

        prepStatement.setObject(1, Boolean.TRUE, Types.BIT);
        prepStatement.execute();
        prepStatement.close();
        connection.close();
    }
}

(btw, the same exception is generated when using setBoolean instead of
setObject.)

Any ideas ?

regards,
Tom



view thread (3+ messages)  latest in thread

Message-ID: <224f3234050620030565ffa711@mail.gmail.com>
Permalink:  ../224f3234050620030565ffa711@mail.gmail.com/
Also on:    postgresql.org/message-id/224f3234050620030565ffa711@mail.gmail.com

 · 

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: tomdzk@gmail.com
  Subject: Re: Exception when inserting boolean values into BIT columns
  In-Reply-To: <224f3234050620030565ffa711@mail.gmail.com>
  References: <224f3234050620030565ffa711@mail.gmail.com>

* 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