我是一个新手,请大家以后多多指教。
这个问题我也看了一些相关的解释,但还是没有用,所以贴出来麻烦大家,谢谢了!
package vote;
import java.sql.*;
public class conn {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:vote";
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) {
rs = null;
try {
connect = DriverManager.getConnection(sConnStr,"dbo","");
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
}
下面是jsp代码
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="voteBean" scope="page" class="vote.conn"/>
<html>
<head>
<title>当前票数统计</title>
<meta content="text/html; charset=gb_2312-80" http-equiv="Content-Type">
<meta content="blueriver" name="Author">
<meta http-equiv="refresh" content="10;URL=show.jsp"></head>
<body bgcolor="#FFFFFF">
<div align="center">
<h1><b>当前票数统计</b> </h1>
<table width="60%" border="1">
<tr bgcolor="#CCCCFF">
<td width="51%">
<div align="center"><font color="#FF0033"><b>候选公司名</b></font></div>
</td>
<td width="49%">
<div align="center"><font color="#FF0033"><b>当前票数</b></font></div>
</td>
</tr>
<%
ResultSet RS_result;
RS_result=voteBean.executeQuery("select * from result");
String companyName;
int voteNum;
while(RS_result.next())
{
companyName=RS_result.getString("candidate");
voteNum=RS_result.getInt("vote_num");
%>
<tr>
<td width="51%" bgcolor="#FFFFFF">
<div align="center"><%=companyName%></div>
</td>
<td width="49%">
<div align="center"><%=voteNum%></div>
</td>
</tr>
<%
}
RS_result.close();
%>
</table>
<hr align="center">
<h2><b>投票人的详细资料</b> </h2>
<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>投票人的IP地址</b></font></div>
</td>
<td>
<div align="center"><font color="#0000FF"><b>投票时间</b></font></div>
</td>
</tr>
<%
ResultSet RS_voter;
RS_voter=voteBean.executeQuery("select * from voter");
String candidate,voterName,voterCompany,voterCountry,ipAdress;
java.util.Date voteTime;
while(RS_voter.next())
{
candidate=RS_voter.getString("candidate");
voterName=RS_voter.getString("voter_name");
voterCompany=RS_voter.getString("voter_company");
voterCountry=RS_voter.getString("voter_country");
ipAdress=RS_voter.getString("ip_address");
voteTime=RS_voter.getDate("vote_time");
%>
<tr>
<td> <%=candidate%></td>
<td> <%=voterName%></td>
<td> <%=voterCompany%></td>
<td> <%=voterCountry%></td>
<td> <%=ipAdress%></td>
<td> <%=voteTime%></td>
</tr>
<%
}
RS_voter.close();
%>
</table>
<p> </p>
</div>
</body>
</html>
下面是出错信息
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.show_jsp._jspService(show_jsp.java:78)
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.请问各位这是怎么回事啊?感激不尽
这个问题我也看了一些相关的解释,但还是没有用,所以贴出来麻烦大家,谢谢了!
package vote;
import java.sql.*;
public class conn {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:vote";
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) {
rs = null;
try {
connect = DriverManager.getConnection(sConnStr,"dbo","");
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
}
下面是jsp代码
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="voteBean" scope="page" class="vote.conn"/>
<html>
<head>
<title>当前票数统计</title>
<meta content="text/html; charset=gb_2312-80" http-equiv="Content-Type">
<meta content="blueriver" name="Author">
<meta http-equiv="refresh" content="10;URL=show.jsp"></head>
<body bgcolor="#FFFFFF">
<div align="center">
<h1><b>当前票数统计</b> </h1>
<table width="60%" border="1">
<tr bgcolor="#CCCCFF">
<td width="51%">
<div align="center"><font color="#FF0033"><b>候选公司名</b></font></div>
</td>
<td width="49%">
<div align="center"><font color="#FF0033"><b>当前票数</b></font></div>
</td>
</tr>
<%
ResultSet RS_result;
RS_result=voteBean.executeQuery("select * from result");
String companyName;
int voteNum;
while(RS_result.next())
{
companyName=RS_result.getString("candidate");
voteNum=RS_result.getInt("vote_num");
%>
<tr>
<td width="51%" bgcolor="#FFFFFF">
<div align="center"><%=companyName%></div>
</td>
<td width="49%">
<div align="center"><%=voteNum%></div>
</td>
</tr>
<%
}
RS_result.close();
%>
</table>
<hr align="center">
<h2><b>投票人的详细资料</b> </h2>
<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>投票人的IP地址</b></font></div>
</td>
<td>
<div align="center"><font color="#0000FF"><b>投票时间</b></font></div>
</td>
</tr>
<%
ResultSet RS_voter;
RS_voter=voteBean.executeQuery("select * from voter");
String candidate,voterName,voterCompany,voterCountry,ipAdress;
java.util.Date voteTime;
while(RS_voter.next())
{
candidate=RS_voter.getString("candidate");
voterName=RS_voter.getString("voter_name");
voterCompany=RS_voter.getString("voter_company");
voterCountry=RS_voter.getString("voter_country");
ipAdress=RS_voter.getString("ip_address");
voteTime=RS_voter.getDate("vote_time");
%>
<tr>
<td> <%=candidate%></td>
<td> <%=voterName%></td>
<td> <%=voterCompany%></td>
<td> <%=voterCountry%></td>
<td> <%=ipAdress%></td>
<td> <%=voteTime%></td>
</tr>
<%
}
RS_voter.close();
%>
</table>
<p> </p>
</div>
</body>
</html>
下面是出错信息
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.show_jsp._jspService(show_jsp.java:78)
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.请问各位这是怎么回事啊?感激不尽
用调试工具单步跟踪很快就可以查出来