• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

how to remove whitespace before inserting

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

am trying to insert values into database, which contains a foreign key...


am sure, the values are exactly same, because am getting database primary key table values in javascript and inserting them into foreign key table in submit.jsp

When I try to print the values.. it shows a lot of whitespaces. How to get rid of these whitespaces before inserting ??? and is this the reason for that error?


 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTH
java.lang.String#trim()
 
author & internet detective
Posts: 40537
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using char or varchar for the field? If the former, it adds whitespace to the end and you'll need to trim after getting it out of the database too.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already used trim(). It's not whitespaces.. it is a newline..
A newline is adding for each field am getting from database ....

In database the field is --- varchar...
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

indu yeturu wrote:I already used trim(). It's not whitespaces.. it is a newline..


You have to be specific and need to tell us the details.

Use java.lang.String#split() to split over the pattern "/r/n" (verify this pattern, I'm not sure) and then join the each array element.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for considering... to be in detail...

am using this function to get the elements (which are stored as context attributes) from servlet.
these context attributes are the elements taken from database...

when I populate these values, the dropdown box is populating fine and when I try to Save into database, it is throwing the error as ...


when I alert these values a blank line is appearing for each option which are populating from servlet..>
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your AJAX server side action, just remove the new line delimiters coming from the SLECECT OPTIONs value. How to remove that, I already explain in my previous post.

Also, before actually executing the query thru JDBC, print it in console, which give you the clear idea about what query is DB trying to execute and you can debug the same.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic