Re: Using java.lang.Character for "char" data type - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Using java.lang.Character for "char" data type
Date
Msg-id alpine.BSO.2.00.1005211813180.22460@leary.csoft.net
Whole thread Raw
In response to Using java.lang.Character for "char" data type  (Віталій Тимчишин <tivv00@gmail.com>)
Responses Re: Using java.lang.Character for "char" data type  (Craig Ringer <craig@postnewspapers.com.au>)
Re: Using java.lang.Character for "char" data type  (Lew <noone@lewscanon.com>)
List pgsql-jdbc

On Fri, 21 May 2010, ??????? ???????? wrote:

> I've tried to use Character to fill "char" column, e.g. like in the next
> test:
> -----
> con.createStatement().execute("create table tst(tcol \"char\")");
> PreparedStatement stmt = con.prepareStatement("insert into tst(tcol)
> values(?)");
> stmt.setObject(1, 'c');
> stmt..executeUpdate();
> -----
> and got 
> Exception in thread "main" org.postgresql.util.PSQLException: Can't infer
> the SQL type to use for an instance of java.lang.Character. Use setObject()
> with an explicit Types value to specify the type to use.
atorg.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statemen
> t.java:1740)
>
> with 8.3-603.jdbc4 driver.
> May be it would be reasonable to treat Character like String of size 1?
>

It would be possible to support setObject for a Character, but be aware
that "char" is not a character long, it's a byte long, so it will fail on
multibyte characters.

Kris Jurka

pgsql-jdbc by date:

Previous
From: Віталій Тимчишин
Date:
Subject: Using java.lang.Character for "char" data type
Next
From: Rod
Date:
Subject: Re: After server restart I get - An I/O error occured while sending to the backend.