Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't convert unicode  RSS feed

 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently I switched a RCP/swing app from using hypersonic to mysql. The problem is that there are some unicode characters in the data. The data now displays with the unicode characters as unicode in the app. I tried printing out the data from the bean and it comes out the same way on the console. If I cut/paste the string from the console and place another print statement inside the bean I get output with unicode from the field and formatted output from the other print statment. Why???
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If those two lines of code produce different output, that's because they have different inputs. So you should start looking there.

I'm a bit confused because I don't understand a lot of things in your post. First of all, all Java characters are Unicode. They all come from the Unicode character set, which includes ASCII as the first 128 code points. Probably you meant that you have some non-ASCII characters.

And I don't understand what it means to "display as unicode". I don't even have a guess for that, so perhaps you could provide an example.

And this console: is it the Windows console, or the Eclipse console, or a Unix shell? They all have different behaviour.

As for MySQL, when you set it up did you configure the database to use UTF-8 as its default character set or did you use something else? UTF-8 is a better choice if you're going to have international inputs.
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"I'm a bit confused because I don't understand a lot of things in your post. First of all, all Java characters are Unicode. They all come from the Unicode character set, which includes ASCII as the first 128 code points. Probably you meant that you have some non-ASCII characters. "

Yes-I am trying to use non ASCII characters such as degree and some other special math characters.

"And I don't understand what it means to "display as unicode". I don't even have a guess for that, so perhaps you could provide an example."

What I mean is that the first line displays as the actual string with escape character "/u00e5" and the second line displays as the interpreted symbol of what that unicode stands for.

"And this console: is it the Windows console, or the Eclipse console, or a Unix shell? They all have different behaviour."

Eclipse console.

In the application as well, the data is not showing up correctly-in otherwords it has the escape character and not the actual degree symbol. I tried just trying to output the symbol as "°" but the formatting gets lost and so "°F" is rendered int he RCP application as "0F"
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Peg wrote:What I mean is that the first line displays as the actual string with escape character "/u00e5" and the second line displays as the interpreted symbol of what that unicode stands for.


Seems to me this could only happen if the database actually contains that string. I'm using MySQL, my database actually contains records with the Unicode degree character (which is U+00B0), and my Swing application displays it perfectly well. Can you run the MySQL workbench and see if that's the case? Putting Java Unicode escape sequences into a database would be a rather unusual approach in my opinion.
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the problem was that when the data was being read in there was an extra "/" being added...why I don't know but I was able to correct it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!