TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
- 今天在修改一老程序时发现数据库(mysql 4.0)里数据本身就是乱码,程序中用commons-fileupload1.0上传组件读取表单数据
- 然后存入数据库,数据库中文乱码。用下面方法临时解决了,记录一下。
- //用于读数据库时由iso8859-1变为GBK
- public String GBKConverter(String s_string){
- try{
- String des = new String(s_string.getBytes("iso8859-1"),"GBK");
- return des;
- }catch(Exception ex){
- String des="";
- return des;
- }
- }
- //用于处理页内生成的中文数据在写入数据库时的处理,由GBK变为iso8859-1
- public String ISOConverter(String s_string){
- try{
- String des =new String(s_string.getBytes("GBK"),"iso8859-1");
- return des;
- }catch(Exception ex){
- String des = "";
- return des
- }
- }
-
复制代码 |
|