Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Servlet/JSP/JSF/JavaFX Script
打印话题 寄给朋友 订阅主题 |
作者 | jsp读取oracle数据中文为何是"?"? |
anber007
发贴: 2 |
于 2004-12-09 21:48
代码如下:请指点一下 其中用了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 |
已读帖子 新的帖子 被删除的帖子 |
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 |