Ibatis Accessing Oracle Database US7ASCII Chinese garbled problem

Source: Internet
Author: User

Today, a problem is encountered, using the Ibatis framework to access the Oracle data encoded as US7ASCII garbled,

It took a long time to find a solution. First Sqlmap-config.xml is configured as follows <sqlmapconfig> <!--<sqlMap> elements are used to include the SQL map map file and other SQL map configuration files. -    <settings  lazyloadingenabled =  usestatementnamespaces = "true" />     <typealias  type = "Com.jerry.spring.util.EncodingStringTypeHandlerCallback" Span style= "font-style:normal; Color:windowtext; " > alias = "ENCODE" /         <typehandler  callback = "ENCODE" javatype = "java.lang.String" />   <sqlmap resource="Com/jerry/spring/model/user_sqlmap.xml" /> <sqlmap resource="Com/jerry/spring/model/timerecord_ Sqlmap.xml " /> </sqlmapconfig>EncodingstringtypehandlercallbackEncodingstringtypehandlercallbackclass InheritanceTypehandlercallback Interface
import java.sql.SQLException; import com.ibatis.sqlmap.client.extensions.ParameterSetter; import com.ibatis.sqlmap.client.extensions.ResultGetter; import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback; public class Encodingstringtypehandlercallback implements typehandlercallback { //Boolean flag = initparam.getdbencoding ("dbencoding"); boolean flag = true;Public Object getresult (resultgetter arg0) throws SQLException { //Latin Character set conversion if(flag) { return stringutil. ISOTOGBK (Arg0.getstring ());        } return arg0.getstring ();     }Public void setparameter (parametersetter setter, Object arg1) throws SQLException { if(arg1 instanceof String)        { //Latin Character set conversion if(flag) {setter.setstring (stringutil. Gbktoiso((String) arg1));            } Else{setter.setstring ((String) arg1);            }        }     }Public Object valueOf (String arg0) { //Latin Character set conversion if(flag) { return stringutil. ISOTOGBK (arg0);         } return arg0;     }}

Stringutil
public class Stringutil { Public static string ISOTOGBK (string s) { If (s = = null | | (S.trim ()). Equals ("")) return s; try {s = new String (S.getbytes ("iso8859-1"), "GB2312"); } Catch (Exception e) {        }     return s;     }      Public static string Gbktoiso (string s) { If (s = = null | | (S.trim ()). Equals ("")) return s; try {s = new String (S.getbytes ("GBK"), "iso-8859-1"); } Catch (Exception e) {        }     return s;     }  }
At this point, the problem of Chinese garbled solution Huan drink attention to personal open source code Https://github.com/zuifengke/windy code under the Medqcwebapp project



From for notes (Wiz)



Ibatis Accessing Oracle Database US7ASCII Chinese garbled problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.