jsp中的奇怪问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 07:46:20
问大家个问题,我写了类,在类内或类间调用一个函数有返回直,但在jsp中调用同一个函数就返回空直
这是什么原因啊,怎么解决,谢谢
package sqlBean;
import java.sql.*;
public class topicBean{
Connection con=null;
ResultSet rs = null;
public topicBean() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e)
{
System.out.println(e.toString());
}
}

public ResultSet getResult(String sql){
rs = null;
try {
con = DriverManager.getConnection("jdbc:odbc:web");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs =stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
/* public static void main(String at[]) throws SQLException, InstantiationException, IllegalAccessExceptio

问题是,你在jsp页面上调用函数的时候,相当于重新声明的类,当然没有值了,不知道你页面是怎么写的,估计是这样

你不应该在jsp页面声明,而是应该用request把已经声明,并且赋值的bean拿过来用,你这么声明,跟 topicBean = null一样