Skip site navigation (1) Skip section navigation (2)

Exception when inserting boolean values into BIT columns

From: Thomas Dudziak <tomdzk(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Exception when inserting boolean values into BIT columns
Date: 2005-06-20 10:05:35
Message-ID: 224f3234050620030565ffa711@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
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

Responses

pgsql-jdbc by date

Next:From: David GagnonDate: 2005-06-20 11:35:57
Subject: Re: Problems with temporary tables created in callable functions
Previous:From: MinalDate: 2005-06-20 06:28:06
Subject: JDBC Connectivity..

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group