• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Apostrophe Problem

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam doing the following steps :

I copy text (For Example: JOHN's) containing a apostrophe from the Microsoft Word document and paste it in a JSP Text box rather then righting JOHN's directly in the text box.

Then submit the jsp so that value in the text box gets entered into the database table .

Now what I am finding gets entered in the table is JOHN�s . So the apostrophe gets converted to � .

I dont know why this is happening or how to resolve this..Please help me regarding this..
[ December 01, 2006: Message edited by: Ben Souther ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
EaseUp
to learn how using the word "Urgent" in your post or subject line can actually slow down or stop responses altogether.
I've removed the offending text for you.

As to your original question...
Nobody on this list will be able to help you unless you tell us the details of how you're writing these values to the database.

What database are you using?
What middleware are you using to write to it.
If it's JDBC, what driver are you using.

What does the Java code that writes to the database look like?
Post the relevant sections.
[ December 01, 2006: Message edited by: Ben Souther ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now what I am finding gets entered in the table is JOHN�s . So the apostrophe gets converted to � .



Sounds like the accursed MS Word "smart" punctuation problem to me - thats not a real ASCII apostrophe. This happens all the time when people cut from Word and paste into browser forms.
This looks like a pretty good review of the problem.
You will have to replace "smart" punctuation with standard characters - Java's regex toolkit is good for this.

Bill
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And this is a good explanation of what to do.
 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William and Paul .. I will try your solution and let you know if I still face any problem ..
 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,

I am trying to use java.util.regex package..
My Code looks like this :

String testName = "Rohit�s"
Pattern p = Pattern.compile("�");
Matcher m = p.matcher(testName);
if(m.find())
{
testName = m.replaceAll("'");
}
The output is Rohit's which is correct.

The thing is that if I have multiple different special characters which can appear in string testName randomly but do not make a specific pattern Iam not able to replace them all.
Ex..

String testName = "�Rohit�s"
Pattern p = Pattern.compile("��");
Matcher m = p.matcher(testName);
if(m.find())
{
testName = m.replaceAll("'");
}
The output is �Rohit's which is incorrect but the output should be 'Rohit's.

Thanks in advance..
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The output is ‘Rohit's which is incorrect but the output should be 'Rohit's.



All I can say is replaceAll works for me - perhaps you really have two different character codes that look like `.

You will of course have to have a Pattern for each non standard character - I make the various Pattern objects static variables since they can be reused.

Bill
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic