[Pljava-dev] char with trailing space, PreparedStatement.setObject & SetString

From: pelletier_32 at sympatico(dot)ca (JEAN-PIERRE PELLETIER)
To:
Subject: [Pljava-dev] char with trailing space, PreparedStatement.setObject & SetString
Date: 2006-06-27 16:07:19
Message-ID: BAY16-F59B99D67B8C5C11857BFB957E0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Hi Thomas,

There are very few char columns on my system, I can easily live with
explicit trim
in my application code, I only wanted to let you guys know.

I am not sure which of the two JDBC implementations is right.
psql and pgadmin would both handle char as expected.
As for JDBC, you might want to know how other dbms are handling this.

Thanks for your reply.
Jean-Pierre Pelletier

>From: Thomas Hallgren <thomas at tada.se>
>To: JEAN-PIERRE PELLETIER <pelletier_32 at sympatico.ca>
>CC: pljava-dev at gborg.postgresql.org
>Subject: Re: [Pljava-dev] char with trailing
>space, PreparedStatement.setObject & SetString
>Date: Tue, 27 Jun 2006 17:47:24 +0200
>
>Hi Jean-Pierre,
>I'm not sure this is incorrect behavior. There's nothing in the spec that
>indicates that String values should be trimmed by setString and setObject.
>On the contrary. Some datatypes (the CHAR in particular) are sensitive to
>whitespace according to the SQL standard. Perhaps the client jdbc driver is
>doing something wrong here?
>
>Regards,
>Thomas Hallgren
>
>
>JEAN-PIERRE PELLETIER wrote:
>>Hi,
>>
>>Trailing space are not handled properly by setObject & setString.
>>
>>PreparedStatement pstmt = connection.prepareStatement(
>> "select * from mytable where mycharcolumn = ?");
>>
>>String myString = "abc ";
>>pstmt.setObject(1, myString); // or setObject(1, myString, Types.CHAR) or
>>setString(1, myString)
>>
>>No rows are returned, but using trim works fine as in:
>>pstmt.setObject(1, myString.trim());
>>
>>My environment is Pl/Java 1.3, Sun JDK 1.5.07, PostgreSQL 8.1.4, Windows
>>XP SP2
>>
>>With PostgreSQL own (non pl/java) jdbc driver, setObject on char works
>>fine without the trim.
>>
>>Thanks,
>>Jean-Pierre Pelletier
>>
>>
>>_______________________________________________
>>Pljava-dev mailing list
>>Pljava-dev at gborg.postgresql.org
>>http://gborg.postgresql.org/mailman/listinfo/pljava-dev
>>

In response to

Browse pljava-dev by date

  From Date Subject
Next Message Eric BOYER 2006-06-28 10:23:54 [Pljava-dev] java.lang.OutOfMemoryError
Previous Message Thomas Hallgren 2006-06-27 15:47:24 [Pljava-dev] char with trailing space, PreparedStatement.setObject & SetString