jsp中的奇怪問題

Jemy發表於2007-09-11
請高手幫忙解決
問大家個問題,我寫了類,在類內或類間呼叫一個函式有返回直,但在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, IllegalAccessException, ClassNotFoundException{
topicBean cdb = new topicBean();
ResultSet rs = cdb.getResult("select * from topic");

try {
while(rs.next()){
System.out.println(cdb.rs.getString("topic_name")+"");
}
} catch (SQLException e) {
System.out.println("2");
e.printStackTrace();
}
} */
}
jsp中的呼叫:
String sql = "select * from topic";
ResultSet rs = topicbean.getResult(sql);
rs 在頁面中有NullPointerException

<jsp:useBean id="topicbean" scope="session" class="sqlBean.topicBean" />
topicbean的申明

相關文章