Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't trim spaces from data in java

Status
Not open for further replies.

bthale

Programmer
Oct 31, 2001
108
0
0
US
I am getting a result from the database and the column is declared as a char(50). I understand that this will be padded with spaces, but I can't get the spaces trimmed in java code using String.trim().
Isn't this strange behaviour? When trying to trim, the data is now a java string. Aren't the java strings and database strings using ANSI char codes? I checked the hex value and it was \\u0020, which is the same as a java space char.
 
Have you tried clearing out the spaces in SQL rather than javascript? I don't know myself, but I'd imagine it might be easiest to clean the data up on the data end of things first.

Also, are you talking about spaces in cells, b/c they are not NULL, but rather have a zero null string value? If so, perhaps you can CONVERT OR CAST[/LINK] the data type, and clear it out that way?
 
Ok - might try the second option as cleaning the DB is not an option.
 
Oh, I didn't mean cleaning up the actual data in the database, but rather having a SQL statement being what you pull rather than pulling against the tables. That way you could have the data formatted the way you want, in SQL, before you ever get java involved. Of course, I've not messed with SQL to java, personally, but it just makes sense to me that it SHOULD be possible. [spineyes]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top