关于javaBean的问题,高分请教~~
conn.class如下
import java.sql.*;
public class conn{
Connection conn=null;
Statement stmt;
ResultSet rs=null;
String sConnStr=** //这里隐藏了,并且这里没有问题的~!!!
public conn(){
try{
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
}catch(SQLException e){
System.err.println("错误连接:"+e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs=null;
try {
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
System.err.println("aq.executeQuerystrSQL: " + sql);
}
return rs;
}
public void executeUpdate(String sql) {
try {
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeUpdate: " + ex.getMessage());
System.err.println("aq.executeUpadatestrSQL: " + sql);
}
}
}
jsp文件如下~~
<%@ page contentType="text/html;charset=ISO8859_1" %>
<%@page import="java.sql.*,java.util.*,java.io.*,conn"%>
<jsp:useBean id="strconn" scope="page" class="conn"/>
<%
ResultSet sqlRst=null;
String strSQL;
int intPageSize;
int intRowCount;
int intPageCount;
int intPage=1;
String strPage;
int i,j,k;
intPageSize=6;
strSQL = "select count(*) from book";
sqlRst = strconn.executeQuery(strSQL);
sqlRst.next();
intRowCount = sqlRst.getInt(1);
sqlRst.close();
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount) intPage = intPageCount;
strSQL = "select * from book order by id desc";
sqlRst = strconn.executeQuery(strSQL);
strPage=request.getParameter("page");
if(strPage!=null){
intPage=Integer.parseInt(strPage);
if(intPage>intPageCount)
{
intPage=intPageCount;
}
else if(intPage<=0)
{
intPage=1;
}
}
//sqlRst.absolute((intPage-1)*intPageSize+1);
i=(intPage-1) * intPageSize;
for(j=0;j<i;j++) sqlRst.next(); %>
<html>
<head>
<title>:::流星宇留言板:::</title>
<LINK href="lybook.css" type=text/css rel=stylesheet>
</head>
<body>
<div align="center">
<table border="0" width="710" height="197" cellspacing="0" cellpadding="0">
<tr>
<td width="710" height="16" colspan="2">
<p align="right"></td>
</tr>
<tr>
<td width="710" height="11" colspan="2">
<p align="right"></td>
</tr>
<center>
<tr>
<td width="277" height="13">
○共有<font color="#FF0000"><%=intRowCount%></font>条留言,共
<font color="#FF0000"><%=intPageCount%></font>页,当前为第<font color="#FF0000"><%=intPage%></font>页</td>
</center>
<td width="433" height="13">
<p align="right">
<a href=../index.jsp><img border="0" src="fh.gif" width="75" height="18"></a>
<a href="postnew.jsp"><img border="0" src="ly.gif" width="74" height="18"></a>
<a href=looks.jsp?page=<%=intPage%>>[刷新]</a>
<%
if(intPage!=1)
{%>
<a href=looks.jsp?page=<%=intPage-1%>>[上一页]</a>
<%}else{%>
[上一页]
<%}
if(intPage!=intPageCount)
{%>
<a href=looks.jsp?page=<%=intPage+1%>>[下一页]</a>
<%}else{%>
[下一页]
<%}%>
<%
if(intPage!=1)
{%>
<a href=looks.jsp?page=1>[首页]</a>
<%}else{%>
[首页]
<%}
if(intPage!=intPageCount)
{%>
<a href=looks.jsp?page=<%=intPageCount%>>[尾页]</a>
<%}else{%>
[尾页]
<%}%></p>
</td>
</tr>
<center>
<tr>
<td width="710" height="152" valign="top" colspan="2">
<table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolorlight="#99CCFF" bordercolordark="#FFFFFF" height="144">
<tr>
<td width="100%" valign="top" height="142"><center>
<%
i=0;
while(i<intPageSize && sqlRst.next()){ %>
<table border="1" width="98%" bordercolorlight="#99CCFF" cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" height="98">
<tr>
<td width="21%" height="11" bgcolor="#99CCFF"><img border="0" src="author.gif" width="23" height="16">留言人:<%=sqlRst.getString("name")%></td>
</center>
</center>
<td width="60%" height="11" bgcolor="#99CCFF">
<p align="left"><img border="0" src="title.gif">主题:
<%=sqlRst.getString("title")%></p>
</td>
<td width="19%" height="11" bgcolor="#99CCFF">
<p align="right"><img border="0" src="homepage.gif">主页<img border="0" src="edit.gif" width="15" height="15">编辑<img border="0" src="admin.gif" width="16" height="16">回复
</td>
</tr>
<center>
<center>
<tr>
<td width="21%" height="83" valign="top">
<table border="0" width="98%" cellspacing="0" cellpadding="0" height="79">
<tr>
<td width="52%" height="79" valign="top" rowspan="4">
<p align="center"><img src=bighead/<%=sqlRst.getString("head")%>.gif></td>
<td width="48%" height="24" valign="middle"></td>
</tr>
<tr>
<td width="48%" height="20" valign="middle"></td>
</tr>
<tr>
<td width="48%" height="20" valign="middle">人气:</td>
</tr>
<tr>
<td width="48%" height="22" valign="middle">货币:</td>
</tr>
</table>
</td>
<td width="79%" height="83" valign="top" colspan="2">
<img src=images/<%=sqlRst.getString("face")%>.gif><%=sqlRst.getString("neirong")%><p>→<font color="#FF0000"><img border="0" src="response.gif" width="18" height="13">站长回复:</td>
</tr>
</table>
<% i++; } %>
</center>
</center>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="278" height="13" valign="top">
○页次:<font color="#FF0000"><%=intPage%></font>/<%=intPageCount%>,每页
<font color="#FF0000"><%=intPageSize%></font>条
</td>
<td width="432" height="13" valign="top">
<form action=looks.jsp method=post>
<p align="right"><img border="0" src="backtopic.gif" width="16" height="16">转到
<input type="text" name=page style="height:18px;width:26px" value=<%=intPage%>>页 </form>
</td>
</tr>
</table>
</div>
</body>
</html>
<%
sqlRst.close();
%>