Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
作者 JSP中如何把中文传进数据库中
y409505





发贴: 4
于 2006-01-02 00:16 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是初学者,在JSP中把中文传进数据库中会出现乱码,请问高手要如何解决这个问题!如果有例子或什么介绍的话请给我发邮件(y2004-y@163.com),谢谢!


作者 Re:JSP中如何把中文传进数据库中 [Re:y409505]
踏浪





发贴: 4
于 2006-01-02 01:49 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在存入数据库前,进行一下编码转换.
就是把你要存的内容,转换成标准码,然后再存.



作者 Re:JSP中如何把中文传进数据库中 [Re:y409505]
y409505





发贴: 4
于 2006-01-02 12:45 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请问标准码是什么,能给个例子吗?谢谢!


作者 Re:JSP中如何把中文传进数据库中 [Re:y409505]
mikecaolei





发贴: 4
于 2006-01-02 13:49 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
做个过滤器就可以解决了


作者 Re:JSP中如何把中文传进数据库中 [Re:y409505]
飘渺一尘烟





发贴: 8
于 2006-01-08 14:44 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
真的很奇怪,我用access,sqlserver和oracle都没有出现这样的问题,不过我用的服务器是resin 。


作者 Re:JSP中如何把中文传进数据库中 [Re:y409505]
junsansi





发贴: 30
于 2006-01-09 18:05 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public static String iso2gb(String str) {
if (str != null) {
str = str.trim();
}
try {
return new String(str.getBytes("iso-8859-1"), "GBK");
} catch (Exception e) {
return str;
}
}



作者 Re:JSP中如何把中文传进数据库中 [Re:y409505]
毒毒√快山





发贴: 23
于 2006-01-24 10:39 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
//中文转换
public String getStr(String str) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859-1");
String temp = new String(temp_t);
return temp;
}
catch (Exception e) {
e.printStackTrace();
}
return "null";
}

我一般是用这个方法的,如果是乱码输入到数据中的话,可以先掉用这个方法,将起转换。不过这个方法的调用也是要看数据的,比如:Sybase就怎么转换到了数据库里也是乱码。如果碰到这样的情况,我就是不转换,让他乱码近数据库。如果在将数据库中的乱码显示在.jsp上的换,就在调用这个方法,就可以拉。不过要注意的是,如果数据库里的是乱码,你在调用和含有SQL语句的函数的时候,不要转换,要乱码对乱码的进行操作。

如果,你在转换后,能在数据库里显示为中文的话,那在读数据库里的数据的时候就不需要转换了

还有的就是,用request的时候,也会有乱码的问题,这个时候就可以用这个方法转换下就OK拉




reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923