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.  [ 2 posts ] 
Author Message
 Post subject: Automatic characterset converting?
PostPosted: Sun Apr 01, 2007 2:46 am 
Newbie

Joined: Sun Apr 01, 2007 2:25 am
Posts: 2
Hi

I'm using MySQL 4.x and the table is configured as EUC-KR characterset.
I cannot change characterset of the DB with my permission.
But I want to store unicode string in the DB.

So, I tried to write string escaper function of my own, like this:

Code:
   public static String escape(String str, CharsetEncoder encoder) {
      if (str == null) {
         return null;
      }
      int strlen=str.length();
      StringBuffer sb = new StringBuffer(strlen*2);
      int i;
      for (i = 0; i < strlen; ++i) {
         char ch = str.charAt(i);
         if(encoder.canEncode(ch)) {
            sb.append(ch);
         }else {
            int intValue = ch;
            sb.append("&#");
            sb.append(intValue);
            sb.append(';');
         }
      }
      
      return sb.toString();
   }


and I also wrote unescaper function. but immediately I noticed that I have to MANUALLY escape and unescape the string in EVERY persisted instance.

Is there a smarter method to do this?


Top
 Profile  
 
 Post subject: Any ideas?
PostPosted: Wed Apr 04, 2007 12:19 am 
Newbie

Joined: Sun Apr 01, 2007 2:25 am
Posts: 2
Any ideas?

More specifically, I want to listen the event occurs when Hibernate trying to serialize any java.lang.String into DB.
Then I could write the filter such as:

Code:
class EscapeEucKr implements StringSerializeFilter {
    public String beforeSerialize(String str) {
        return escape(str, encoder);
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.