使用useBean时中文乱码
文件源代码:
package com;
import java.sql.*;
import db.*;
public class newManage
{
ConnDB con= new ConnDB();
private String userid,password,qy,username,bm,job,type;
public void setUserid(String u){userid=u;}
public String getUserid(){return userid;}
public void setPassword(String p){password=p;}
public String getPassword(){return password;}
public void setQy(String q){qy=q;}
public String getQy(){return qy;}
public void setUsername(String n){username=n;}
public String getUsername(){return username;}
public void setBm(String b){bm=b;}
public String getBm(){return bm;}
public void setJob(String j){job=j;}
public String getJob(){return job;}
public void setType(String t){type=t;}
public String getType(){return type;}
public void updateDatabase(){
Connection conn=null;
String userid2,qy2,username2,job2,bm2,type2;
try {
conn=con.mygetConn();
String sql= "Insert Into Manages(userid,[password],qy,username,job,bm,type) values(?,?,?,?,?,?,?) ";
PreparedStatement perstmt=conn.prepareStatement(sql);
userid2 = new String(userid.getBytes( "GBK "), "GBK ");
perstmt.setString(1,userid2);
perstmt.setString(2,password);
perstmt.setString(3,qy);
perstmt.setString(4,username);
perstmt.setString(5,job);
perstmt.setString(6,bm);
perstmt.setString(7,type);
perstmt.executeUpdate();
}catch(Exception e) {
e.printStackTrace();
}
}
}
问题 : userid存入数据库中是乱码?请求帮助,谢谢!
------解决方案--------------------改为这样:userid2 = new String(userid.getBytes( "ISO-8859-1 "), "GBK ");