• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

jsp, oracle, single quotes

Hello guys (gals),

       I am writing a jsp page with an oracle backend. It has a large text area where a description will be written and sometimes apostrophes will be used. As we all know, apostrophes or single quotes bust be escaped before they are inserted into the database. I need a javascript replace function to handle the single quote in my text area and I would like to have some clear, commented code, that is why my question will be worth 500 points!

Thanks!
0
astrohelp
Asked:
astrohelp
  • 7
  • 6
1 Solution
 
ZvonkoSystems architectCommented:
Why do you not want to convert the apostrophes on server side? Tha wold be the recomandded place. You never know wether scripting is enabled or not on client side.

Also what would you like to have instead of apostrophes? And when do you want to convert them back to apostrophes for display?

0
 
astrohelpAuthor Commented:
It is a controlled environment, so scripting will be enabled. I want to replace ' with /' or even ' with '' <--- one single quote replaced with two single quotes so that it can be inserted into my table without any problems.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
all you need to do is use double apostrophes when inserting into the database, and thats only if you're using a sql statement such as INSERT or UPDATE. If you are just opening up a new RS and doing the RS.AddNew method then you do not need to convert anything.

for javascript:
var txtDesc = txtDesc.replace("single-quote", "single-quote single-quote")

for vbscript:
txtDesc = Replace("single-quote", "single-quote single-quote")

I spelled out what quotes to use for readability. When you implement this you would need to use the actual ' on the leyboard. And ZVonko is right, server side would be the way to go.

B.D.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
sorry, for vbscript, it should be:

txtDesc = Replace(txtDesc, "single-quote", "single-quote single-quote")
0
 
astrohelpAuthor Commented:
ok, how would i go about this on the server side?
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
say the field name is txtDesc:

strTxtDesc = Request.Form("txtDesc")
strTxtDesc = Replace(strTextDesc, "'", "''")
double, single, double quotes<-------|    |----------->here double quote, two single quotes, and a double

then in your insert statement, add the value strTextDesc

B.D.
0
 
astrohelpAuthor Commented:
when i try this code i get an error "Method Replace blah blah blah not found in class" What version did they impliment this class?
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
can you post the full error text please?
0
 
astrohelpAuthor Commented:
Method Replace(java.lang.String, java.lang.String, java.lang.String) not found in class _it._mis__it__update__call3.
      vtxtsolution = Replace(vtxtsolution, "'", "''");
                           
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
use the following:

vtxtsolution = vtxtsolution.replace("'", "''")
0
 
astrohelpAuthor Commented:
hmmmm     new error

 Incompatible type for method. Can't convert java.lang.String to char.
      vtxtsolution = vtxtsolution.replace("'", "''");
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try declaring vtxtsolution as a string before you get the value of the description field. other than that im not sure
0
 
astrohelpAuthor Commented:
i am already doing that...
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
check out this question:
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_20839542.html

when i first read your question i thought it was in javascript, not jsp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now