8.0 beta4: Exception with setBoolean on char column

Started by Laferriere, Alover 21 years ago2 messagesbugs
Jump to latest
#1Laferriere, Al
ALaferriere@Sciforma.com

The web page http://www.postgresql.org/news/235.html says report
any/all problems in 8.0 to this address, so...

The following java code works fine on 7.4:

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

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

Statement stmt = conn.createStatement();

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

stmt.close();

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

pstmt.setBoolean(1, false);

pstmt.executeUpdate();

But, in 8.0.0beta4 on we get:

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)

OS = Windows XP Pro

Java version 1.5.0-b64

JDBC driver: pgdev.307.jdbc3.jar

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

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.

Thanks.

-al laferriere

#2Kris Jurka
books@ejurka.com
In reply to: Laferriere, Al (#1)
Re: 8.0 beta4: Exception with setBoolean on char column

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