Wrong SqlType for boolean columns

From: fortunasliebling(at)gmx(dot)de
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Wrong SqlType for boolean columns
Date: 2010-07-28 07:26:58
Message-ID: 20100728072658.14770@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello everyone,

i found out that my postgres driver maps a boolean column to the sqlType -7, wich is java.sql.Types.BIT and not java.sql.Types.Boolean (Boolean is 16). This is a very strange behavior.

I think this is a bug within the jdbc-driver.

link to JavaDoc:
http://java.sun.com/javase/6/docs/api/constant-values.html#java.sql.Types.BOOLEAN

the code i used to test this:

//returns a connection to the database
Connection con = ConnectionManager.getConnection();
PreparedStatement prep = con.prepareStatement("select isboolean from test");
ResultSet rs = prep.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println(rsmd.getColumnType(1));
System.out.println(rsmd.getColumnTypeName(1));
rs.close();
prep.close();
con.close();

definition of table:
CREATE TABLE test
(
id serial NOT NULL,
"name" character varying NOT NULL DEFAULT ''::character varying,
"number" integer DEFAULT 1,
date date DEFAULT now(),
isboolean boolean DEFAULT true,
CONSTRAINT test_pkey PRIMARY KEY (id)
)

the output of this program is:
-7
bool

but it should be:
16
bool

I tested this with:
postgresql-8.3-605.jdbc3.jar
postgresql-8.4-701.jdbc3.jar
postgresql-8.4-701.jdbc4.jar

Server is PostgreSQL 8.4.4 on x86_64-pc-linux-gnu by gcc4-4.real (Ubuntu)...

Im using java-sdk 6.

greetings
Michael
--
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2010-07-28 08:59:47 Re: Wrong SqlType for boolean columns
Previous Message Panon, Paul-Andre 2010-07-28 04:30:32 getMetaData().getTables() behaviour with JDBC3 8.3 & 8.4 drivers on windows