Обсуждение: Using char fields with 7.1.3 driver

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

Using char fields with 7.1.3 driver

От
Дата:
I've found after using a CMP J2EE entity bean, along with the 7.1.3 jdbc
driver, queries return the entire char field back while using char(), but
varchar returns just the value of the field back.


for example,

create table test_table(
id integer primary key not null,
name varchar(255)
);

vs.

create table test_table(
id integer primary key not null,
name char(255)
);



When returning the name value from the first table it looks something like
this (single quotes are in just to show the entire field)

'Name'


However, when using the second table this happens:

'Name


'

notice the 249 characters of whitespace.


I can easily get around this using .trim(), but I'm wondering if that
should be in the jdbc driver itself (as I'll have to go through a bit of
code looking for string values being returned).

Or is this something in the database software itself that you can configure?


Also, Is there a "real" Website for the postgres jdbc driver?
http://jdbc.postgresql.org seems a little outdated.

I wouldn't mind being able to grab the source for the driver and putting in
this small fix myself.

-Jeff



Re: Using char fields with 7.1.3 driver

От
"David Wall"
Дата:
I'm not a JDBC expert, but this is pretty much the way I'd expect it to
work.  If you a have fixed length field, then the field should return that
many characters.  The varchar implies it's variable length, so trailing
spaces would then not be included.

David


Re: Using char fields with 7.1.3 driver

От
Bruce Momjian
Дата:
> I can easily get around this using .trim(), but I'm wondering if that
> should be in the jdbc driver itself (as I'll have to go through a bit of
> code looking for string values being returned).

char() is fixed length, varchar isn't.

>
> Or is this something in the database software itself that you can configure?
>
>
> Also, Is there a "real" Website for the postgres jdbc driver?
> http://jdbc.postgresql.org seems a little outdated.
>
> I wouldn't mind being able to grab the source for the driver and putting in
> this small fix myself.

    http://jdbc.fastcrypt.com

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026