回 帖 发 新 帖 刷新版面

主题:jsp中javabean访问数据库,运行jsp是出错了,大虾帮忙啊!

javabean代码:  
 
package  student;  
import  java.sql.*;  
 
public  class  conn{  
           String  sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";  
           String  sConnStr="jdbc:odbc:student";  
           Connection  connect=null;  
           ResultSet  rs=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();  
                                   rs=stmt.executeQuery(sql);  
                       }  
                       catch(SQLException  ex){  
                                   System.err.println(ex.getMessage());  
                       }  
                       return  rs;  
           }  
}  
 
访问javabean的jsp源文件代码:  
<%@page  contentType="text/html;charset=GBK"%>  
<%@page  language="java"  import="java.sql.*"%>  
<jsp:useBean  id="connDbBean"  scope="page"  class="student.conn"/>  
<html>  
   <head><title>test  db  connect</title></head>  
<body  bgcolor="#FFFFFF">  
<div  align="center">  
     <table  width="60%"  border="1">  
         <tr  bgcolor="#CCCCFF">  
             <td  width="50%">  
                 <div  align="center"><font  color="#FF0033"><b>姓名</b></font></div>  
             </td>  
             <td  width="25%">  
                 <div  align="center"><font  color="#FF0033"><b>性别</b></font></div>  
             </td>  
             <td  width="25%">  
                 <div  align="center"><font  color="#FF0033"><b>分数</b></font></div>  
             </td>  
         </tr>  
<%  
ResultSet  RS_result=connDbBean.executeQuery("select  *  from  table1");  
String  studentName="";  
String  studentSex="";    
int  studentScore=0;  
while(RS_result.next()){  
         studentName=RS_result.getString("name");  
         studentSex=RS_result.getString("sex");  
         studentScore=RS_result.getInt("score");  
%>  
   <tr>  
       <td  width="50%"  bgcolor="#FFFFFF">  
           <div  align="center"><%=studentName%></div>  
       </td>  
         <td  width="25%"  bgcolor="#FFFFFF">  
           <div  align="center"><%=studentSex%></div>  
       </td>  
         <td  width="25%"  bgcolor="#FFFFFF">  
           <div  align="center"><%=studentScore%></div>  
       </td>  
   </tr>  
<%  
}  
RS_result.close();  
%>      
</table>  
</div>  
</body>  
</html>  
 
在浏览器中输入http://localhost:8080/myjsp/conn_db.jsp出现如下错误信息:(myjsp为tomcat的虚拟目录)  
 
type  Exception  report  
 
message    
 
description  The  server  encountered  an  internal  error  ()  that  prevented  it  from  fulfilling  this  request.  
 
exception    
 
org.apache.jasper.JasperException  
           org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)  
           org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)  
           org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)  
           javax.servlet.http.HttpServlet.service(HttpServlet.java:802)  
 
 
root  cause    
 
java.lang.NullPointerException  
           org.apache.jsp.conn_005fdb_jsp._jspService(conn_005fdb_jsp.java:75)  
           org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)  
           javax.servlet.http.HttpServlet.service(HttpServlet.java:802)  
           org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)  
           org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)  
           org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)  
           javax.servlet.http.HttpServlet.service(HttpServlet.java:802)  
 
 
note  The  full  stack  trace  of  the  root  cause  is  available  in  the  Apache  Tomcat/5.0.28  logs.  
 
大虾请帮帮忙看看怎么回事啊?我已经运行了好几个jsp调用javabean都没出问题啊,怎么就这个有问题?

回复列表 (共1个回复)

沙发


重新新建odbc数据源  要是系统dsn不是用户dsn

我来回复

您尚未登录,请登录后再回复。点此登录或注册