jsp 提取sql 数据库 分页显示
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();Stringu...
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=zzh";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);%>
显示内容
<%@ include file="db.jsp"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>Database</title>
</head>
<body><%=session.getMaxInactiveInterval()%> <%=session.getAttribute("login")%>
<center><table border="2">
<tr>
<th>学号 </th>
<th>姓名 </th>
<th>学院 </th>
<th>修改 </th>
<th>删除 </th>
</tr>
<%
String sql="select * from z";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><a href="change.jsp?xuehao=<%=rs.getString(1)%>">修改</a>
<td><a href="del.jsp?xuehao=<%=rs.getString(1)%>">删除</a>
</tr>
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</table>
<%out.print("数据库操作成功,恭喜你");%>
<a href="addform.html">添加记录</a>
<a href="login0.html">用户登录</a>
<a href="reg.html">注册</a>
<a href="ser.html">搜索</a>
<a href="out.jsp">注销</a>
<a href="myinf.jsp">我的信息</a>
</body>
</html> 展开
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=zzh";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);%>
显示内容
<%@ include file="db.jsp"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>Database</title>
</head>
<body><%=session.getMaxInactiveInterval()%> <%=session.getAttribute("login")%>
<center><table border="2">
<tr>
<th>学号 </th>
<th>姓名 </th>
<th>学院 </th>
<th>修改 </th>
<th>删除 </th>
</tr>
<%
String sql="select * from z";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><a href="change.jsp?xuehao=<%=rs.getString(1)%>">修改</a>
<td><a href="del.jsp?xuehao=<%=rs.getString(1)%>">删除</a>
</tr>
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</table>
<%out.print("数据库操作成功,恭喜你");%>
<a href="addform.html">添加记录</a>
<a href="login0.html">用户登录</a>
<a href="reg.html">注册</a>
<a href="ser.html">搜索</a>
<a href="out.jsp">注销</a>
<a href="myinf.jsp">我的信息</a>
</body>
</html> 展开
3个回答
展开全部
从ResultSet rs=stmt.executeQuery(sql); 开始后面这么写:
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
int i;//设置一页显示的记录数
intPageSize = 4;//取得待显示页码
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
sqlRst.last();
intRowCount = sqlRst.getRow();//获得当前行号
intPageCount = (intRowCount+intPageSize-1) /intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
int thepage=(intPage-1)*intPageSize;
int n=0;
rs.absolute(thepage+1);
while (n<(pageSize)&&!rs.isAfterLast()){%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><a href="change.jsp?xuehao=<%=rs.getString(1)%>">修改</a>
<td><a href="del.jsp?xuehao=<%=rs.getString(1)%>">删除</a>
</tr>
<%
}%>
<form name="sinfo" method="post" action="" onSubmit="return testform(this)">
第<%=currPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(currPage>1){%><a href="?">首页</a><%}%>
<%if(currPage>1){%><a href="?page=<%=currPage-1%>上一页</a><%}%>
<%if(currPage<pageCount){%><a href="?page=<%=currPage+1%>">下一页</a><%}%>
<%if(pageCount>1){%><a href="?page=<%=pageCount%>">尾页</a><%}%>
跳到<input type="text" name="page" size="4" style="font-size:9px">页
<input type="submit" name="submit" size="4" value="GO" style="font-size:9px">
</form>
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
int i;//设置一页显示的记录数
intPageSize = 4;//取得待显示页码
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
sqlRst.last();
intRowCount = sqlRst.getRow();//获得当前行号
intPageCount = (intRowCount+intPageSize-1) /intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
int thepage=(intPage-1)*intPageSize;
int n=0;
rs.absolute(thepage+1);
while (n<(pageSize)&&!rs.isAfterLast()){%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><a href="change.jsp?xuehao=<%=rs.getString(1)%>">修改</a>
<td><a href="del.jsp?xuehao=<%=rs.getString(1)%>">删除</a>
</tr>
<%
}%>
<form name="sinfo" method="post" action="" onSubmit="return testform(this)">
第<%=currPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(currPage>1){%><a href="?">首页</a><%}%>
<%if(currPage>1){%><a href="?page=<%=currPage-1%>上一页</a><%}%>
<%if(currPage<pageCount){%><a href="?page=<%=currPage+1%>">下一页</a><%}%>
<%if(pageCount>1){%><a href="?page=<%=pageCount%>">尾页</a><%}%>
跳到<input type="text" name="page" size="4" style="font-size:9px">页
<input type="submit" name="submit" size="4" value="GO" style="font-size:9px">
</form>
展开全部
LS代码我看过,基本都完成了.
还有些小改动
sqlRst.last();
intRowCount = sqlRst.getRow();//获得当前行号
//在计算页数的时候应该更加清晰一些
if(intRowCount%intPageSize==0)
{
intPageCount=intRowCount/intPageSize;
}
else
intPageCount=intRowCount/intPageSize+1;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
int thepage=(intPage-1)*intPageSize;
int n=0;
rs.absolute(thepage+1);
for(n=0;i<intPageSize;n++)
{
%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><a href="change.jsp?xuehao=<%=rs.getString(1)%>">修改</a>
<td><a href="del.jsp?xuehao=<%=rs.getString(1)%>">删除</a>
</tr>
<%
if(rs.next())//游标移动
continue;
else
break;
}%>
<form name="sinfo" method="post" action="" onSubmit="return testform(this)">
第<%=currPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(currPage>1){%><a href="?">首页</a><%}%>
<%if(currPage>1){%><a href="?page=<%=currPage-1%>上一页</a><%}%>
<%if(currPage<pageCount){%><a href="?page=<%=currPage+1%>">下一页</a><%}%>
<%if(pageCount>1){%><a href="?page=<%=pageCount%>">尾页</a><%}%>
跳到<input type="text" name="page" size="4" style="font-size:9px">页
<input type="submit" name="submit" size="4" value="GO" style="font-size:9px">
</form>
还有些小改动
sqlRst.last();
intRowCount = sqlRst.getRow();//获得当前行号
//在计算页数的时候应该更加清晰一些
if(intRowCount%intPageSize==0)
{
intPageCount=intRowCount/intPageSize;
}
else
intPageCount=intRowCount/intPageSize+1;
//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
int thepage=(intPage-1)*intPageSize;
int n=0;
rs.absolute(thepage+1);
for(n=0;i<intPageSize;n++)
{
%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><a href="change.jsp?xuehao=<%=rs.getString(1)%>">修改</a>
<td><a href="del.jsp?xuehao=<%=rs.getString(1)%>">删除</a>
</tr>
<%
if(rs.next())//游标移动
continue;
else
break;
}%>
<form name="sinfo" method="post" action="" onSubmit="return testform(this)">
第<%=currPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(currPage>1){%><a href="?">首页</a><%}%>
<%if(currPage>1){%><a href="?page=<%=currPage-1%>上一页</a><%}%>
<%if(currPage<pageCount){%><a href="?page=<%=currPage+1%>">下一页</a><%}%>
<%if(pageCount>1){%><a href="?page=<%=pageCount%>">尾页</a><%}%>
跳到<input type="text" name="page" size="4" style="font-size:9px">页
<input type="submit" name="submit" size="4" value="GO" style="font-size:9px">
</form>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询