Обсуждение: SQL CHAR type using setByte()

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

SQL CHAR type using setByte()

От
"David Wall"
Дата:
I have a Java byte field that I'm trying to store in the database.  It has a value of (byte)'0' which is a binary 48.
 
When I use preparedStatement.setByte() with that value, to store in a Postgresql CHAR field, it only stores a '4'.  It's as if the binary 48 were being converted to a String and then the first byte from the string was stored in the database.  I'm using 7.1.1beta4.
 
Does this make any sense?  Am I using the wrong SQL type or the wrong JDBC PreparedStatement set call?
 
Thanks,
David

Re: SQL CHAR type using setByte()

От
"David Wall"
Дата:
A quick review of the JDBC code shows that in fact everything that you pass
into the driver is converted to a String first.

Since Java char fields are 16 bit unicode characters, how does one go about
using the SQL type CHAR(1), which by default is only one byte (there is no
call setChar() in JDBC)?  I see that the driver has a type TINYINT, but I
have no idea what that maps to in Postgresql or in Java, though it sure
sounds like a byte to me.

David