我想这么做,但是总报错,请问为什么 关于 javabean
----admin_message_list.jsp-----------
<%@ page import="java.sql.*" %>
<jsp:include page="admin_head.jsp" />
<HTML>
<HEAD>
<TITLE> 信息列表 </TITLE>
<style type="text/css">
<!--
@import url("Images/admin_right.css");
-->
</style>
</HEAD>
<BODY>
<table class=tableBorder width="90%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<TH class="tableHeaderText" colSpan="6" height="25">信息列表</th>
</tr>
<tr>
<td class="forumRow" width="60" height="25" nowrap><div align="center">信息编号</div></td>
<td class="forumRow"><div align="center">信息标题</div></td>
<td class="forumRow"><div align="center">信息内容</div></td>
<td class="forumRow" widht="60" nowrap><div align="center">作者</div></td>
<td class="forumRow" widht="40" nowrap><div align="center">修改</div></td>
<td class="forumRow" widht="40" nowrap><div align="center">删除</div></td>
</tr>
<jsp:useBean id="listMessage" class="com.neusoft.vicky.ConnectToDataBase" />
<%
String temp;
listMessage.connect();
String sqlString = "SELECT * FROM vicky_message ORDER BY no DESC";
ResultSet rs=listMessage.select(sqlString);
while (rs.next())
{
%>
<tr>
<td class="forumRow" nowrap><div align="center"><%=rs.getInt("no")%></div></td>
<td class="forumRow"><div align="left">
<%
temp= rs.getString("title");
// ***************************** 问题所在
temp=listMessage.decodeChar(temp); //报错
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
out.println(temp);
%>
</div></td>
<td class="forumRow"><div align="center">
<%
temp= rs.getString("content");
out.println(temp);
%>
</div></td>
<td class="forumRow" nowrap><div align="center"><%=rs.getString("send_user")%></div></td>
<td class="forumRow" widht="40" nowrap><div align="center"><a href="">修改</a></div></td>
<td class="forumRow" widht="40" nowrap><div align="center"><a href=admin_del.jsp?db=vicky_message&no=<%=rs.getInt("no")%>>删除</a></div></td>
</tr>
<%
}
listMessage.disconnect();
%>
</table>
<br />
</form>
<jsp:include page="admin_foot.jsp" />
</BODY>
</HTML>
--ConnectToDataBase.java--
package com.neusoft.vicky;
import java.sql.*;
import java.util.*;
public class ConnectToDataBase
{
private String chineseChar;
String queryString;
String error;
Connection conn=null;
Statement myStatement=null;
ResultSet rs=null;
public void connect() throws ClassNotFoundException,SQLException,Exception
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.7:1521:HLJUBISP","neusoft","neusoft");
}
catch (ClassNotFoundException e)
{
error="ClassNotFoundException:Could not locate DB driver.";
throw new ClassNotFoundException(error);
}
catch(SQLException e)
{
error="SQLException:Could not connect to database.";
throw new SQLException (error);
}
catch(Exception e)
{
error="Excetpion: An unknown error occurred while connecting to database";
throw new Exception(error);
}
}
public void disconnect () throws SQLException
{
try
{
if (conn!=null)
{
conn.close();
}
}
catch(SQLException e)
{
error="SQLException : Unable to close the database connection.";
throw new SQLException (error);
}
}
public ResultSet select(String myString) throws SQLException ,Exception
{
if (conn!=null)
{
try
{
queryString=encodeChar(myString);
myStatement = conn.createStatement();
rs=myStatement.executeQuery(queryString);
}
catch (SQLException e)
{
error="SQLException:Could not execute the query.";
throw new SQLException(error);
}
catch (Exception e)
{
error="an exception occured.";
throw new Exception(error);
}
return rs;
}
else
{
error="Exception : Connection to database was lost.";
throw new Exception(error);
}
}
public void insert(String myString) throws SQLException ,Exception
{
if (conn!=null)
{
try
{
queryString=encodeChar(myString);
myStatement = conn.createStatement();
rs=myStatement.executeQuery(queryString);
}
catch (SQLException e)
{
error="SQLException:Could not execute the query.";
throw new SQLException(error);
}
catch (Exception e)
{
error="an exception occured.";
throw new Exception(error);
}
}
else
{
error="Exception : Connection to database was lost.";
throw new Exception(error);
}
}
public void delete(String myString) throws SQLException ,Exception
{
insert(myString);
}
public void update(String myString) throws SQLException ,Exception
{
insert(myString);
}
//字符转换函数
public String encodeChar(String myString)
{
try
{
if(myString==null)
{
myString="";
}
else
{
myString = new String(myString.getBytes("ISO8859_1"), "GBK");
}
return myString;
}
catch(Exception e)
{
return "";
}
}
public String decodeChar(String myString)
{
try
{
if(myString==null)
{
myString="";
}
else
{
myString = new String(myString.getBytes("GBK"),"ISO-8859-1" );
}
return myString;
}
catch(Exception e)
{
return "";
}
}
};
========================================
<%
temp= rs.getString("title");
// ***************************** 问题所在
temp=listMessage.decodeChar(temp); //报错
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
out.println(temp);
%>
temp=listMessage.decodeChar(temp); //报错
但是
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
却能通过
请高手指教.谢谢!!!!!!!