• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to remove whitespace before inserting

 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • 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?


 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34851
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic