Reading of string with quotes around it - PROBLEM - PLEASE HELP?
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.
[1499 byte] By [
CHEERS] at [2007-9-26 3:30:54]

paste ur code.... how ur sending value to DB?Vinay
Are you sure that you use the needed escape chars with the quotes? (And which DB is this?)
Hi.use escape chars...String s="\"This is a test\"";out.println(s); // this will print as "This is a test"orreplace the particular chars with thier ascii value before inserting into db and replace again while getting back from db.
you need to double the quotes if you want the quotes to be inserted in the database
If I use this line within my bean:
String strTitle = resource.getTitle();
this line should get the title that has been selected from the drop down menu and it does perfectly well if the string does not have quotes around it. If the string within the database (MS SQL) does have quotes around it though, I get absolutely nothing if I try to print it out. Even if I try to escape the quotes within the bean with \", I still have the same problem....
I have not tried using the prepared statement yet. Could someone expalin to me why this will help over just using a plain statement? Would just by using the prepared statement get rid of the quotes or any other special characters automatically?
Right now I am using:
m_Statement = m_Connection.createStatement();
m_Statement.executeUpdate(strFinalSQLAdd);
This works fine to do the query and display them in my drop down menu?
Please help?
CHEERS at 2007-6-29 11:57:00 >

PreparedStatement pstmt = con.prepareStatement( "insert into tableName( col1, col2, col3) values (?,?,?)" );
pstmt.setString(1, str1 );
pstmt.setString(2, str2 );
pstmt.setString(3, str3 );
pstmt.executeUpdate();
this should help u using PreparedStatement
If u use PreparedStatement
insert statement formed will look this
if str1 contains "x1"
str2 contains "x2"
str3 contains "x3"
insert into tableName( col1, col2, col3) values ('"x1"','"x2"','"x3"')
Double quotes within single quotes
If u use Statement then
String sql = "insert into tableName( col1, col2, col3) values ('" + str1 + "','"+str2+ "','"+str3 +")";
then sql string will be terminated at str1 itself
Vinay
How will this work if I can not even get the string that was selected from the drop down if it had quotes around it?
CHEERS at 2007-6-29 11:57:00 >

paste your coe here, and we will solve the problem.
The code is too large to post.
Let me explain it better now I guess than...
I have solved the problem with keeping someone from entering a string in a text box with quotes so thank you to all those that helped.
I now have the problem with a drop down menu. I need a way of removing the quotes from the string the user selects from the drop down menu if it does have quotes around it. After removing the quotes I then want to set that as the value selected for the drop down and submit the form.
Either by doing it in the JSP or (which I would prefer), doing it within the bean somehow. I know prepared statements have been suggested but I have still not been able to get a reply or read anything on how they would remove any special characters from a value that may be in a column of my table with double quotes around it.
Please help if you can and ask any questions you may have for clarification....
Thank you...
CHEERS at 2007-6-29 11:57:00 >
