This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes PreparedStatement pads spaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement pads spaces " Watch "PreparedStatement pads spaces " New topic
Author

PreparedStatement pads spaces

Vic Dayton
Greenhorn

Joined: Apr 21, 2002
Posts: 7
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

Joined: May 30, 2002
Posts: 1400
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.


- Varun
Vic Dayton
Greenhorn

Joined: Apr 21, 2002
Posts: 7
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement pads spaces