MySQL stores the HTML of a page, which should be of a long field and be of the Blob type. garbled characters are found after the page is retrieved. The solution is to expand a typehandler.
Public class myblobtypehandler extends basetypehandler <string >{## specified character set Private Static final string default_charset = "UTF-8"; @ override public void setnonnullparameter (preparedstatement ps, int I, string parameter, jdbctype) throws sqlexception {bytearrayinputstream bis; try {## # convert string to byte stream Bis = new bytearrayinputstream (parameter. getbytes (default_charset);} catch (unsupporteden Codingexception e) {Throw new runtimeexception ("Blob Encoding Error! ");} Ps. setbinarystream (I, BIS, parameter. length () ;}@ override Public String getnullableresult (resultset RS, string columnname) throws sqlexception {blob = Rs. getblob (columnname); byte [] returnvalue = NULL; If (null! = BLOB) {returnvalue = blob. getbytes (1, (INT) blob. length ();} Try {### convert byte to string return new string (returnvalue, default_charset);} catch (unsupportedencodingexception E) {Throw new runtimeexception ("Blob Encoding Error! ") ;}@ Override Public String getnullableresult (callablestatement CS, int columnindex) throws sqlexception {blob = cs. getblob (columnindex); byte [] returnvalue = NULL; If (null! = BLOB) {returnvalue = blob. getbytes (1, (INT) blob. length ();} Try {return new string (returnvalue, default_charset);} catch (unsupportedencodingexception e) {Throw new runtimeexception ("Blob Encoding Error! ");}}}
Configure the following in the configuration file:
<Result column = "menu" property = "menu" typehandler = "myblobtypehandler"/>
Done.