Topic: jsp读取oracle数据中文为何是"?"?

  Print this page

1.jsp读取oracle数据中文为何是"?"? Copy to clipboard
Posted by: anber007
Posted on: 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>

2.Re:jsp读取oracle数据中文为何是"?"? [Re: anber007] Copy to clipboard
Posted by: mfc42d
Posted on: 2004-12-13 15:18

写入数据库的时候把ISO转为GBK,jiuok了
检索的时候不用转码的

3.Re:jsp读取oracle数据中文为何是"?"? [Re: anber007] Copy to clipboard
Posted by: SaviourJLF
Posted on: 2004-12-15 10:39

看你数据库的编码。Oracle新建数据库默认编码是iso8859_1
如果是这样你的转码有问题。。

以上。。

4.Re:jsp读取oracle数据中文为何是"?"? [Re: anber007] Copy to clipboard
Posted by: xhxasdf
Posted on: 2004-12-23 10:56

在你的title里面加上
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

这句话

5.Re:jsp读取oracle数据中文为何是"?"? [Re: anber007] Copy to clipboard
Posted by: ?笮?闵?讣
Posted on: 2005-01-04 02:48

<%@ page contentType = "text/html;charset = gb2312"%>
<%@ page language = "java"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.io.*"%>
后面加上:<%request.setCharacterEncoding("gb2312");%>
就OK了

对了,你先看看你数据库里是不是乱码啊,我怀疑你插入数据的时候有可能就是乱码


   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