Exception when inserting boolean values into BIT columns

Поиск
Список
Период
Сортировка
От Thomas Dudziak
Тема Exception when inserting boolean values into BIT columns
Дата
Msg-id 224f3234050620030565ffa711@mail.gmail.com
обсуждение исходный текст
Ответы Re: Exception when inserting boolean values into BIT columns
Список 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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Minal
Дата:
Сообщение: JDBC Connectivity..
Следующее
От: David Gagnon
Дата:
Сообщение: Re: Problems with temporary tables created in callable functions