Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PostgreSQL trailing spaces

843859Jan 26 2007 — edited Jan 28 2007
I have a problem with inserting and updating database in postgresdatabase.
When I do something with database using PreparedStatement every string has trailing spaces at the end. How to avoid this situation?
Example:

PreparedStatement p = con.prepareStatement("insert into hospital_user (login, callmanager_user, pin, css, user_type_id, surname, name, phone) values (?, ?, ?, ?, ?, ?, ?, ?)");
p.setString(1, this.login);
p.setString(2, this.callmanagerUser);
p.setInt(3, this.pin);
p.setString(4, this.css);
p.setInt(5, this.userTypeId);
p.setString(6, this.surname);
p.setString(7, this.name);
p.setInt(8, this.phone);
if (1 == p.executeUpdate()) {
return "ok";
}

althoug this.login = 'foo' it is inserted as 'foo ' (trailing spaces at the end) if login is defined in DB as varchar(20) I have foo with 17 spaces at the end.
I use Postgres 7.4 and JDBC postgresql-8.2-504.jdbc3.jar

Any ideas hov to trim this spaces?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 25 2007
Added on Jan 26 2007
6 comments
564 views