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

您没有登录

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

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 jsp读取oracle数据中文为何是"?"?
anber007





发贴: 2
于 2004-12-09 21:48 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
代码如下:请指点一下
其中用了trans()转换函数还是不行,不得其解。我用的是Win2000 Server + Oracle9i
<%@ page contentType = "text/html;charset = gb2312"%>
<%@ page language = "java"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.io.*"%>
<%! String trans(String chi)
{
String result = null;
byte temp[];
try
{
temp = chi.getBytes("gb2312");
result = new String(temp);
}catch(UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
return result;
}
%>
<html>
<head>
<title>连接oralce</title>
</head>
<body>
<table border = 1>
<tr><td>ID</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%
request.setCharacterEncoding("gb2312");
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:myoracle";
String uid = "scott";
String pwd = "tiger";
Connection con = DriverManager.getConnection(url,uid,pwd);
Statement stmt = con.createStatement();
ResultSet rst = stmt.executeQuery("select * from book");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+ trans(rst.getString("BOOKID")) + "</td>");
out.println("<td>"+ trans(rst.getString("BOOKNAME")) + "</td>");
out.println("<td>"+ trans(rst.getString("PUBLISHER")) + "</td>");
out.println("<td>"+ trans(rst.getString("PRICE")) + "</td>");
out.println("</tr>");
}
rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>


littledeer1974 edited on 2004-12-09 21:50



关于Jute Forum的长期发展给官方的建议

话题树型展开
人气 标题 作者 字数 发贴时间
2886 jsp读取oracle数据中文为何是"?"? anber007 1624 2004-12-09 21:48
2394 Re:jsp读取oracle数据中文为何是"?"? mfc42d 36 2004-12-13 15:18
2607 Re:jsp读取oracle数据中文为何是"?"? SaviourJLF 58 2004-12-15 10:39
2835 Re:jsp读取oracle数据中文为何是"?"? xhxasdf 89 2004-12-23 10:56
2468 Re:jsp读取oracle数据中文为何是"?"? ?笮?闵?讣 282 2005-01-04 02:48

reply to postflat 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