Обсуждение: 8.0 beta4: Exception with setBoolean on char column

Поиск
Список
Период
Сортировка

8.0 beta4: Exception with setBoolean on char column

От
"Laferriere, Al"
Дата:
The web page http://www.postgresql.org/news/235.html  says report
any/all problems in 8.0 to this address, so...

=20

The following java code works fine on 7.4:

=20

                        Class.forName("org.postgresql.Driver");

                        Connection conn =3D
DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgresdb
","xxx","");

=20

                        Statement stmt =3D conn.createStatement();

                        stmt.execute("CREATE TABLE tt (ans char(1))");

                        stmt.close();

=20

                        PreparedStatement pstmt =3D
conn.prepareStatement("INSERT INTO tt (ans) VALUES (?)");

                        pstmt.setBoolean(1, false);

                        pstmt.executeUpdate();

=20

But, in 8.0.0beta4 on we get:

=20

java.sql.SQLException: ERROR: column "ans" is of type character but
expression is of type boolean

      at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecu
torImpl.java:1187)

      at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImp
l.java:990)

      at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
138)

      at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stateme
nt.java:347)

      at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdb
c2Statement.java:294)

      at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2S
tatement.java:249)

      at BoolTest.main(BoolTest.java:18)

=20

=20

OS =3D Windows XP Pro

Java version 1.5.0-b64

JDBC driver: pgdev.307.jdbc3.jar

=20

There is no problem with setString(1,"0") or when tt column is declared
bool.

=20

Also noted that on 8.0, trying to do a setString(1, "0") on a bool
column throws  "column "ans" is of type boolean but expression is of
type text" where in 7.4 there is no problem.

=20

Thanks.

=20

-al laferriere

Re: 8.0 beta4: Exception with setBoolean on char column

От
Kris Jurka
Дата:
On Mon, 1 Nov 2004, Laferriere, Al wrote:

> [can't call setBoolean on char or setString on boolean]
>

This is the expected behavior.  The 8.0 release of the JDBC driver
includes strong typing.  Previous versions of the driver did simple
string substitution, a = ? was transformed to a = '0' before being sent to
the server.  Now it uses a true prepared statement on the server side
which needs the correct types given to it.

Kris Jurka