SQL server2000插入中文时出现乱码如何解决? 在线等...

dreamlins 2006-03-17 11:55:38
jsp中调用bean:以下是bean里面的方法

public void executeUpdate(String sql)throws Exception{
sql=new String(sql.getBytes("GBK"),"ISO8859_1");
try{
conn=DriverManager.getConnection(sConnStr,username,password);
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
conn.close();
stmt.close();
}
catch(SQLException ex){
System.out.println("sql.executeUpdate:"+ex.getMessage());
}
}
这样做也不行!!!
...全文
281 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
guo__peng 2006-03-17
  • 打赏
  • 举报
回复
String str=new String(sql.getBytes("iso-8859-1"),"GB2312");
这样应该就可以了,这是编码原因造成的。

关于过滤器,tomcat下有一个例子。
dreamlins 2006-03-17
  • 打赏
  • 举报
回复
过滤器?能简单介绍一下吗?
ibiswang 2006-03-17
  • 打赏
  • 举报
回复
另外,如果你的sql是由上个页面中传过来的,注意也调用request.setCharactEncoding来设定为GBK或GB2312,注意,你上个页面中的charactencoding应当中对应的gbk或gb2312..
ibiswang 2006-03-17
  • 打赏
  • 举报
回复
不用转码,在你的jsp中通过response.setCharactEncoding的方法将输出改为GBK或GB2312就行了,另外,注意应当在jsp执行代码的第一行就这么设定。
doway 2006-03-17
  • 打赏
  • 举报
回复
new String(sql.getBytes("GBK"),"ISO8859_1");

大多数情况下这样做刚刚好搞反了,通常应该是:

new String(sql.getBytes("ISO8859-1"),"GBK");

另外,这样做编码转换早就过时了,应该使用过滤器。
crazycl 2006-03-17
  • 打赏
  • 举报
回复
往数据库中插入纪录时,先对中文纪录进行编码转换,然后再插入就不会出现问题了
aiyahujiejun 2006-03-17
  • 打赏
  • 举报
回复
在构造SQL之前 针对那些参数转码 不要对整条SQL转
试试吧
xinxideyilian 2006-03-17
  • 打赏
  • 举报
回复
<%!
public String GBToUnicode(String strIn)
{
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))return strIn;
try{
byte[] b = strIn.getBytes("ISO8859_1");
strOut = new String(b,"GBK");
}
catch(Exception e)
{}
return strOut;
}
%>
rickhunterchen 2006-03-17
  • 打赏
  • 举报
回复
过滤器的例子:
http://www.blogjava.net/rickhunter/articles/33571.html

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧