Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement pads spaces

 
Vic Dayton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have encountered a problem that if I used PreparedStatement to insert records, then JDBC will pad spaces in the fields.
But if I used regular statement, then the insert is fine.
Is this is normal? Is there any way I can fix this problem?
Any advice is greatly appreciated.
Thanks
-VD
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the datafield giving you this problem is of type CHAR ? if yes, Try VARCHAR and see if this works as in the SQL standard, CHAR is a fixed length data type. In many DB's (not all), that means every character must match, including size and trailing blanks.
 
Vic Dayton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. The datafield is Varchar.
But I found the real problem is the the setString() method. I still don't know why.
I found a work around is to supply all the value in the update SQL statement when construct the preparedStatement. I need this work around use the JSTL SQL tag. :-(
Thanks.
-VD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic