急,在线。。。。。。。。。。。。。。。。
我建了一个jsp文件,用来执行数据库查询,其中调用一个javabean文件(编译通过)
代码如下:jsp文件:
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="NPMBean" scope="page" class="NPM.conn" />
<html>
<head>
<title>硕博论文查询结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#ffffff">
<div align="center">
<h1><b>硕博论文查询结果</b></h1>
<table width="100%" border="1">
<tr bgcolor="#ffcccc">
<td>
<div align="center"><font color="#0000ff"><b>题目</b></font></div>
</td>
<td><div align="center"><font color="#0000ff"><b>作者</b></font></div></td>
<td><div align="center"><font color="#0000ff"><b>导师</b></font></div></td>
<td><div align="center"><font color="#0000ff"><b>上传时间</b></font></div></td>
<td><div align="center"><font color="#0000ff"><b>下载时间</b></font></div></td>
<td><div align="center"><font color="#0000ff"><b>内容简介</b></font></div></td>
</tr>
<%
String keyword,way;
String strSQL;
keyword=request.getParameter("keyword");
keyword=(keyword);
way=request.getParameter("way");
strSQL="";
if (way.trim().equals("1")){
strSQL="SELECT * FROM M&DPaper where theme='"+keyword+"'";
}
if (way.trim().equals("2")){
strSQL="SELECT * FROM M&DPaper where author='"+keyword+"'";
}
ResultSet RSa=NPMBean.executeQuery(strSQL);
while(RSa.next()){
String srch_title,author,teacher;
java.util.Date aTime,uTime;
srch_title=RSa.getString("theme");
author=RSa.getString("author");
teacher=RSa.getString("tutor");
aTime=RSa.getDate("atime");
uTime=RSa.getDate("utime");
%>
<tr>
<td> <%=srch_title%></td>
<td> <%=author%></td>
<td> <%=teacher%></td>
<td> <%=aTime%></td>
<td> <%=uTime%></td>
</tr>
<%
}
RSa.close();
%>
</table>
<p> </p>
</body>
</html>
而javabean文件代码如下:
package NPM;
import java.sql.*;
public class conn{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:NPM";
Connection connect=null;
ResultSet RSa=null;
public conn(){
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
connect=DriverManager.getConnection(sConnStr);
Statement stmt=connect.createStatement();
RSa=stmt.executeQuery(sql);
}
catch(SQLException e){
System.err.println(e.getMessage());
}
return RSa;
}
}
已知数据库和数据源都已建好,但再运行出现空指针错误,代码如下:
500 Servlet Exception
java.lang.NullPointerException
at _search__jsp._jspService(/search.jsp:39)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:497)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:244)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:484)
--------------------------------------------------------------------------------
Resin 2.1.6 (built Fri Nov 8 08:18:18 PST 2002)
请问这是什么原因啊????????
at _search__jsp._jspService(/search.jsp:39)
39行正是while(RSa.next()){