-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Charset Encoding issues
PostPosted: Thu Jan 11, 2007 12:30 pm 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
I am using MySQL with JConnector 5 and hibernate 3.1

I have now read ALL posts on charsets and I still have a problem.
I have created my tables with engine = InnoDB DEFAULT CHARSET=utf8;
I have put these values in hibernate.cfg.xml
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>

I have inserted in the database just for testing the norwegian charachters 'æøå', but still when I try to read it from Hibernate it is read like this: æøå

Have I forgotten something? I can mention that I have tried to write UTF8, utf-8 and utf8 but still it doesnt work. I also tried with the hibernate.connection.charSet but that didnt work either.

Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 3:55 pm 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:18 am
Posts: 28
I haven't tested this but I'm pretty sure you have to use "utf8" instead of "UTF-8" or else MySQL won't understand what you mean.

Everything works here with hibernate.connection.characterEncoding=utf8, no need for hibernate.connection.useUnicode=true.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 5:31 pm 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
I did use utf8 on my mysql database. See it says engine = InnoDB DEFAULT CHARSET=utf8;

:/

I also tried to write that hibernate.connection.characterEncoding = utf8 in hibernate.properties, but that didnt work. Could you please paste your encoding stuff which you have on hibernate.properties and hibernate.cfg.xml , maybe I have written something incorrectly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 5:16 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
I sort of fixed this issue. Although there still are some problems.

I managed to fix that when you enter insert from the command line in mysql now it works. I had to use the set names utf8;

But still when I do an import job from java which retrieves data from a xls file, the charset is still wrong.
Maybe the file is ISO and i am trying to read with UTF-8. I don't know. :/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 5:48 am 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 17
I've been facing the same issues with files. Java also needs to know the encoding of the file it is reading before you can read from it. Which means you are probably reading the file using a different encoding and inserting wrong data into the database.

This is part of my test code. Maybe it can be of some help.

Code:
File file = new File("myfile.txt");
RandomAccessFile raf = new RandomAccessFile(file, "rw");
FileInputStream fis = new FileInputStream(file);
FileChannel fc = raf.getChannel();
MappedByteBuffer mBuf;
CharBuffer cb;
CharsetDecoder decoder = Charset.forName("ISO8859_15").newDecoder();
try{
    if(fc.isOpen()){
        mBuf = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
        ByteBuffer bb = encoder.encode(decoder.decode(mBuf));
        //do the reading
        ...
    }
}


If anyone has a better solution, its more than welcome for me as well! ;o)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 6:08 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
Thank you so much. I can't believe I didn't think of this problem before hand. Now it works great!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.