This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't read string with quotes around it in my bean method - Please help?????

 
Moined Mogul
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP where the user enters a string that is then placed within a column of a table of a database using a JDBC connection. I have found that the user can enter a string with quotes around it and it enters the table fine. I can then query that column fine and place all the values of the column into an array that I use in a drop down menu displaying all of them in another JSP. My propblem now is that if I try and take that value that is selected in the drop down menu that has quotes around it (values without quotes work fine) and use that value to place in another JDBC update statement, I get an emptry string.
For example, if I have something like this that appears in my drop down menu, it will not work:
"This is a test"
If I have the same string without quotes there is no problem:
This is a test
I believe it has something to do with the string being read like this when it has quotes around it:
""This is a test""
I am not quite sure how to deal with this problem since the correct value appears in the database table and can be seen in the drop down even with quotes around it. Whenever I try to use that selected string that has quotes around it though by accessing it in my bean method, I get a totally empty string.
If anyone could please make some suggestions on how to solve this I would greatly appreciate it. This is quote urgent, so the sooner you could answer the better.
Thank you VERY much in advance.
 
Sunetra Saha
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try escaping the quotes(if present) with a '\'?
 
arpit singla
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moined
i am also facing same kind of problem, try using prepared Statement if that helps, though i am not sure on that. if prepared statement could parse the the quotes and pass the values properly for the JDBC query..
arpit
 
Moined Mogul
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried escaping them within the bean method but that did not work...
I will look into using a prepared statement for it...could someone give me an example of using a prepared statement for query.....
 
Moined Mogul
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really do not understand why it works fine for displaying the values with quotes in my drop down menu but when I try to retrieve that selected value from the drop down with quotes around it, I get nothing???
By using the prepared statement, will that automatically get rid of any special characters within the string???
Could someone please clarify this???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic