Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trim Trailing Spaces from Field

 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading a database to get a Customer Name Char 40, Even though the Customer Name is 16 long , When I read it from the Database its 40 long. So I use the Code below to trim the traling spaces, I then Send it to an input Text box in my JSP which is a UPDATE form. If I then try to update this field , it wont let me unless I hit EOF first. Is there a way to fix this ? What am I missing ? Thanks

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you:
  • using a VARACHAR DB type so that you dont have to wirry about trailing spaces to begin with?
  • or, using the builtin String trim method rather than inventing the wheel?
  • or, using the JSTL trim function rather than inventing the wheel?


  • I have no idea what you mean by "hitting EOF".
     
    Joe Brigs
    Ranch Hand
    Posts: 70
    IBM DB2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I will use the String Trim Function. I'm over 50 , I'm a Mainframe guy. So maybe EOF is a hold over but to be more clear on what I meant. If I do the keyboard combination of EOF ( end of file) which removes the invisible characters after the 1st 16 characters. Once I do the EOF I can key past the 16 characters etc. Also I work for a big shop, and were going against an existing os/390 DB2 database so changing a columns definition isn't that easy in my situation, Since there are a lot of backend programs that would need to be changed. Thanks for the help
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65220
    95
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ah yes, dealing with legacy databases. Always a joy!

    In any case, if you want to trim in the Java code, using the String class' trim() method is the way to go. Trimming in the JSP itself should use the JSTL's trim() EL function.

    P.S. Over 50 here too.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic