<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.Date"%>
<html>
<head>
<style>
<!--
tr {font-size:10pt}
body {font-size:10pt}
a:link {color:blue;text-decoration:none}
a:visited {color:blue;text-decoration:none}
a:active {color:red;text-decoration:none}
a:hover {color:red;text-decoration:underline}
-->
</style>
</head>
<body bgcolor=LightBlue>
<% //加载驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//建立与ACCESS数据库,数据源名称为classdate
//ACCESS数据库没有设定用户名和密码
Connection con=DriverManager.getConnection("jdbc:odbc:classdate");
//建立Statement对象
Statement statement=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=null;
%>
<table width="391" border="1" bordercolor=RoyalBlue align="center" bgcolor=lightblue>
<tr align="center">
<td bgcolor=lightblue width=112 >班级</td>
<td bgcolor=lightblue width=113 >姓名</td>
<td bgcolor=lightblue width=144 >总分</td>
</tr>
<%
String class1=request.getParameter("class1");
String name=request.getParameter("name");
rs=statement.executeQuery("select * from classdate where class1='"+class1+"' and name='"+name+"'");
int sum=0;
while(rs.next())
{
int count=rs.getInt("count");
sum=sum+count;
String String_SQL="insert into zhongfen(class1,name,sum) values('"+class1+"','"+name+"','"+sum+"')";
statement.executeUpdate(String_SQL);
out.println("<tr align=center>");
out.println("<td width=150>"+rs.getString("class1")+"</td>");
out.println("<td width=50>"+rs.getString("name")+"</td>");
out.println("<td width=150>"+rs.getString("sum")+"</td>");
}
rs.close();
statement.close();
con.close();
%>
</table>
</body>
</html>
<html>
<head>
<style>
<!--
tr {font-size:10pt}
body {font-size:10pt}
a:link {color:blue;text-decoration:none}
a:visited {color:blue;text-decoration:none}
a:active {color:red;text-decoration:none}
a:hover {color:red;text-decoration:underline}
-->
</style>
</head>
<body bgcolor=LightBlue>
<% //加载驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//建立与ACCESS数据库,数据源名称为classdate
//ACCESS数据库没有设定用户名和密码
Connection con=DriverManager.getConnection("jdbc:odbc:classdate");
//建立Statement对象
Statement statement=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=null;
%>
<table width="391" border="1" bordercolor=RoyalBlue align="center" bgcolor=lightblue>
<tr align="center">
<td bgcolor=lightblue width=112 >班级</td>
<td bgcolor=lightblue width=113 >姓名</td>
<td bgcolor=lightblue width=144 >总分</td>
</tr>
<%
String class1=request.getParameter("class1");
String name=request.getParameter("name");
rs=statement.executeQuery("select * from classdate where class1='"+class1+"' and name='"+name+"'");
int sum=0;
while(rs.next())
{
int count=rs.getInt("count");
sum=sum+count;
String String_SQL="insert into zhongfen(class1,name,sum) values('"+class1+"','"+name+"','"+sum+"')";
statement.executeUpdate(String_SQL);
out.println("<tr align=center>");
out.println("<td width=150>"+rs.getString("class1")+"</td>");
out.println("<td width=50>"+rs.getString("name")+"</td>");
out.println("<td width=150>"+rs.getString("sum")+"</td>");
}
rs.close();
statement.close();
con.close();
%>
</table>
</body>
</html>
<html>
<head>
<style>
<!--
tr {font-size:10pt}
body {font-size:10pt}
a:link {color:blue;text-decoration:none}
a:visited {color:blue;text-decoration:none}
a:active {color:red;text-decoration:none}
a:hover {color:red;text-decoration:underline}
-->
</style>
<title>数据库中记录分页显示实例</title>
</head><body bgcolor=LightBlue>
<%
//try
//{
//加载驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//建立与ACCESS数据库,数据源名称为classdate
//ACCESS数据库没有设定用户名和密码
Connection con=DriverManager.getConnection("jdbc:odbc:classdate");
//建立Statement对象
Statement statement=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=null;
%>
<table width="391" border="1" bordercolor=RoyalBlue align="center" bgcolor=lightblue>
<tr align="center">
<td bgcolor=lightblue width=112 >班级</td>
<td bgcolor=lightblue width=113 >姓名</td>
<td bgcolor=lightblue width=144 >总分</td>
</tr>
<%
String class1=(String)rs.getString("class1");
String name=(String)rs.getString("name");
rs=statement.executeQuery("select * from classdate where class1='"+class1+"' and name='"+name+"'");
int sum=0;
while(rs.next())
{
int count=rs.getInt("count");
sum=sum+count;
String String_SQL="insert into zhongfen(class1,name,sum) values('"+class1+"','"+name+"','"+sum+"')";
statement.executeUpdate(String_SQL);
out.println("<tr align=center>");
out.println("<td width=150>"+rs.getString("class1")+"</td>");
out.println("<td width=50>"+rs.getString("name")+"</td>");
out.println("<td width=150>"+rs.getString("zhongfen")+"</td>");
}
rs.close();
statement.close();
con.close();
%>
</table>
</body>
</html>
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.SQL_005fPages2_jsp._jspService(SQL_005fPages2_jsp.java:82)
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.
--------------------------------------------------------------------------------Apache Tomcat/5.0.28
String class1=(String)rs.getString("class1");
String name=(String)rs.getString("name");
rs=statement.executeQuery("select * from classdate where class1='"+class1+"' and name='"+name+"'");
你应该知道为什么会NullPointerException了吧
出错信息为:
description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.SQL_005fPages2_jsp._jspService(SQL_005fPages2_jsp.java:115)
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)
root cause java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1。
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
org.apache.jsp.SQL_005fPages2_jsp._jspService(SQL_005fPages2_jsp.java:94)
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.
--------------------------------------------------------------------------------
你怎么能在rs里用它呢