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

Pounds Signs (£) being displayed as Question Marks (?)

Hi,

I am writing an applcation using the Apache Struts Framework with a MySQL database.

There is a field in the database which holds text which users would often inlude a pound sign (£) as part of the text. This is stored ok, as I have looked at the data using the MySQL Query Browser. The problem is that when the data is read back from the database, any pound signs are replaced with a ? when output to the system console (and a y with an accent if it is output to the JSP).

I've had a read around and I think this is something to do with character encoding, but I might be wrong since all the fixes I've tried so far have been unsuccessful.

Cheers for any help,
Pete
0
playerone
Asked:
playerone
  • 10
  • 8
  • 5
  • +3
1 Solution
 
objectsCommented:
could just be the font you're using doesn't have that character
0
 
playeroneAuthor Commented:
I can't see how to add useUnicode and characterEncoding parameters to my connection string, Orion won't start.

My datasource is in an XML file:
  <data-source
  class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
  name="Go4BplgDS"
  location="jdbc/myDS"
  xa-location="jdbc/xa/MysqlXADataSource"
  ejb-location="jdbc/myDS"
  connection-driver="com.mysql.jdbc.Driver"
  username="pete"
  password="pete"
  url="jdbc:mysql://localhost/myDatabase"
  inactivity-timeout="30"
  />

if I add them to the URL, eg url="jdbc:mysql://localhost/myDatabase?useUnicode=true&characterEncoding=UTF-8", i get an error from Orion complaining that &characterEncoding being a character entity, and if i try to add them as separate attributes, eg useUnicode="true" on a new line, there are errors about useUnicode not being a valid attribute.

Is there another place I'm supposed to put these?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hoomanvCommented:
The JDBC Driver should be Unicode compliant
we can specify that in connection string
jdbc:mysql://localhost/database?useUnicode=true&characterEncoding=UTF-8
im not using Apache Struts to tell you how you can do this
0
 
objectsCommented:
have you checked the value of the character coming back from the db to see if it actually is wrong?
0
 
playeroneAuthor Commented:
i've figured out how to add the useUnicode and characterEncoding they needed to be added like this:
url="jdbc:mysql://localhost/go4bplgdev?useUnicode=true&amp;characterEncoding=utf-8"

Still no luck though :(

"have you checked the value of the character coming back from the db to see if it actually is wrong?"
how do you mean? I've looked in the database at what is actually being stored and it is pound signs (£), but like i say the problem is that java's system.out.println outputs them as ?'s and when it is passed to the jsp, they come out as y's with accents.
0
 
hoomanvCommented:
in your jsp use
contentType="text/html;charset=UTF8"/>
0
 
hoomanvCommented:
i meant UTF-8
0
 
playeroneAuthor Commented:
"contentType="text/html;charset=UTF-8"/>"

no, thats not made any difference :(
0
 
hoomanvCommented:
system.out.println prints bytes in ascii char set, ignoring 2 byte chars and just prints the low byte
i meant set this in your jsp
setContentType("text/html; charset=utf-8");
and then if you are viewing the result page in browser be sure to set the encoding
i.e. in firefox you must set the character encoding to unicode
if that doesn't help, you are still getting an invalid character from mysql
0
 
Giant2Commented:
£ is a special char. Try to use charset=iso-8859-1

Hope this could help you.
Bye, Giant.
0
 
hoomanvCommented:
may be
but open up cmd and type ALT + 0163 (in numpad)
you can see £ is not even a unicode char
0
 
playeroneAuthor Commented:
"system.out.println prints bytes in ascii char set, ignoring 2 byte chars and just prints the low byte
i meant set this in your jsp
setContentType("text/html; charset=utf-8");
and then if you are viewing the result page in browser be sure to set the encoding
i.e. in firefox you must set the character encoding to unicode
if that doesn't help, you are still getting an invalid character from mysql"

yeah, i put that in the header of the jsp, still the same. changin firefox's encoding to unicode made them display as sorta diamond shapes :S

"open up cmd and type ALT + 0163 (in numpad) you can see £ is not even a unicode char"

did this and it displayed a £ okay, so i take it that means that its not the command window messing things up?

"£ is a special char. Try to use charset=iso-8859-1"
the jsp was set to this originally, i think the problem is when its getting the data from the database, since its correct in the database, but different when displayed on the system.out console.
0
 
Giant2Commented:
>"£ is a special char. Try to use charset=iso-8859-1"
>the jsp was set to this originally, i think the problem is when its getting the data from the database, since its correct in the >database, but different when displayed on the system.out console.
Surely! You must convert before display in the console.
0
 
playeroneAuthor Commented:
so how do i do this convert?

i've tried many different connection url settings:

url="jdbc:mysql://localhost/go4bplgdev?useUnicode=false&amp;characterEncoding=ISO-8859-1"
url="jdbc:mysql://localhost/go4bplgdev?useUnicode=true&amp;characterEncoding=ISO-8859-1"
url="jdbc:mysql://localhost/go4bplgdev?useUnicode=false&amp;characterEncoding=ISO8859_1"
url="jdbc:mysql://localhost/go4bplgdev?useUnicode=true&amp;characterEncoding=ISO8859_1"

and nothing seems to make any difference!! :'(
0
 
Giant2Commented:
the correct could be
>useUnicode=true&characterEncoding=ISO-8859-1
0
 
Giant2Commented:
...ISO-8859-1 even in your jsp page (don't forget)!

Bye, Giant.
0
 
radarshCommented:
If you are using struts bean:write tag to render the value, try setting the filter attribute
to true. It might help

________
radarsh
0
 
playeroneAuthor Commented:
"If you are using struts bean:write tag to render the value, try setting the filter attribute
to true. It might help"

cheers, i'll give it a try on monday!
0
 
playeroneAuthor Commented:
"If you are using struts bean:write tag to render the value, try setting the filter attribute
to true. It might help"

no, thats not worked, darn it! any other suggestions?
0
 
Giant2Commented:
>....ISO-8859-1 even in your jsp page
Do you have checked?
0
 
playeroneAuthor Commented:
sorry, yeah:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
0
 
playeroneAuthor Commented:
I've managed to find the solution!

seems java had trouble getting data from the database when it is stored as a blob, using a text field instead seems to have fixed the problem!

cheers, for your help!
0
 
hoomanvCommented:
you did not tell anything about how you stored that string and we all assume you are using varchar
the data in a BLOB is treated as binary data and is never converted to another encoding while the data in a CLOB is treated as character data and is converted as necessary.
0
 
playeroneAuthor Commented:
yeah, sorry about that, just didn't realise that would make a difference.

any idea how i close this question since i've answered it myself?
0
 
hoomanvCommented:
I answer the topic question not how to close this thread
http://dev.mysql.com/doc/refman/5.0/en/cj-configuration-properties.html
here you can find how to set clobCharacterEncoding as you have learned from the previous posts how to configure connection characterEncoding
0
 
GranModCommented:
PAQed with points refunded (250)

GranMod
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 8
  • 5
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now