当前位置: 技术问答>java相关
怎么能把cmd下输入的汉字输入数据库的时候不会乱码?给分多多
来源: 互联网 发布时间:2015-09-27
本文导语: DataInputStream username=new DataInputStream(System.in); System.out.print("请输入姓名:); usernamestr=username.readLine(); 输入汉字后 hState.executeUpdate("INSERT INTO Tel(USERID,USERNAME,USERTEL) VALUES('"+i+"','"+usernamestr+"','"+usertelstr+"')"); 连接SQL数据库,在表...
DataInputStream username=new DataInputStream(System.in);
System.out.print("请输入姓名:);
usernamestr=username.readLine();
输入汉字后
hState.executeUpdate("INSERT INTO Tel(USERID,USERNAME,USERTEL) VALUES('"+i+"','"+usernamestr+"','"+usertelstr+"')");
连接SQL数据库,在表里看的时候,发现汉字变成了????
怎么解决这个问题啊
|
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}