public List findAllNewsList()
{
String sql = "select * from news ORDER BY id LIMIT 0 , 3";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
List newsList = new ArrayList();
try{
conn = DB.getConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
News news = new News();
news.setNewsId(rs.getInt("id"));
news.setTitle(rs.getString("title"));
news.setType(rs.getString("type"));
news.setCreateDate(rs.getDate("newstime"));
newsList.add(news);
}
}catch(Exception e){
e.printStackTrace();
}finally{
DB.closeConn(conn);
DB.closeStmt(stmt);
DB.closeStmt(stmt);
}
return newsList;
}这里我想用 limit 进行分页 String sql = "select * from news ORDER BY id LIMIT " + firstRecord + "," + RecordSize ;
然后 怎么处理下 在jsp中能正常现实下 谢谢
{
String sql = "select * from news ORDER BY id LIMIT 0 , 3";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
List newsList = new ArrayList();
try{
conn = DB.getConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
News news = new News();
news.setNewsId(rs.getInt("id"));
news.setTitle(rs.getString("title"));
news.setType(rs.getString("type"));
news.setCreateDate(rs.getDate("newstime"));
newsList.add(news);
}
}catch(Exception e){
e.printStackTrace();
}finally{
DB.closeConn(conn);
DB.closeStmt(stmt);
DB.closeStmt(stmt);
}
return newsList;
}这里我想用 limit 进行分页 String sql = "select * from news ORDER BY id LIMIT " + firstRecord + "," + RecordSize ;
然后 怎么处理下 在jsp中能正常现实下 谢谢
就给个 例子页面你 自己看哈!!!!!!!!!<%@page pageEncoding="gb18030"%>
<%@ page import="java.sql.*,java.util.*"%>
<%@ page import="com.*"%><%
boolean islogined = false;
String adminlogined = (String) session.getAttribute("admin");
if (adminlogined != null && adminlogined.trim().equals("true")) {
islogined = true;
}
int pageno = 1;
final int page_size = 10;
String strpageno = request.getParameter("pageno");
if (strpageno != null && !strpageno.trim().equals("")) {
try {
pageno = Integer.parseInt(strpageno);
} catch (Exception e) {
pageno = 1;
}
} if (pageno <= 0) {
pageno = 1;
}
int totalpage = 0;
List<Article> articles = new ArrayList<Article>();
Connection conn = DB.getConn();
Statement stmt = DB.createstmt(conn);
Statement stmtcount = DB.createstmt(conn);
ResultSet rscount = DB.Exequery(stmtcount,
"select count(*) from article where pid=0");
rscount.next();
int totalrecords = rscount.getInt(1);
totalpage = (totalrecords + page_size - 1) / page_size;
if (pageno > totalpage) {
pageno = totalpage;
}
int startpost = (pageno - 1) * page_size;
ResultSet rs = DB.Exequery(stmt,
"select * from article where pid=0 order by pdate asc limit "
+ startpost + " , " + page_size);
while (rs.next()) {
Article a = new Article();
a.initFromrs(rs);
articles.add(a);
}
DB.close(rs);
DB.close(rscount);
DB.close(stmtcount);
DB.close(stmt);
DB.close(conn);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Java|Java世界_中文论坛|ChinaJavaWorld技术论坛 : Java语言*初级版</title>
<meta http-equiv="content-type" content="text/html; charset=GBK">
<link rel="stylesheet" type="text/css" href="images/style.css"
title="Integrated Styles">
<script language="JavaScript" type="text/javascript"
src="images/global.js"></script>
<link rel="alternate" type="application/rss+xml" title="RSS"
href="http://bbs.chinajavaworld.com/rss/rssmessages.jspa?forumID=20">
<script language="JavaScript" type="text/javascript"
src="images/common.js"></script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td width="140">
<img src="images/header-left.gif"
alt="Java|Java世界_中文论坛|ChinaJavaWorld技术论坛" border="0">
</td>
<td>
<img src="images/header-stretch.gif" alt="" border="0" height="57"
width="100%">
</td>
<td width="1%">
<img src="images/header-right.gif" alt="" border="0">
</td>
</tr>
</tbody>
</table>
<br>
<div id="jive-forumpage">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr valign="top">
<td width="98%">
<p class="jive-breadcrumbs">
论坛: Java语言*初级版(模仿)
</p>
<p class="jive-description">
探讨Java语言基础知识,基本语法等 大家一起交流 共同提高!谢绝任何形式的广告
</p>
</td>
</tr>
</tbody>
</table>
<div class="jive-buttons">
<table summary="Buttons" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="jive-icon">
<a href="article.jsp"><img src="images/post-16x16.gif"
alt="发表新主题" border="0" height="16" width="16"> </a>
</td>
<td class="jive-icon-label">
<a id="jive-post-thread" href="Post.jsp">发表新主题</a><a
href="article.jsp"></a>
</td>
<td class="jive-icon-label">
<a id="jive-post-thread" href="article.jsp">返回到总列表</a><a
href="article.jsp"></a>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr valign="top">
<td>
<span class="nobreak"> 共<%=totalpage%>页/第<%=pageno%>页<a
href="articleflat.jsp?pageno=1">[首页</a><span
class="jive-paginator"> | <a
href="articleflat.jsp?pageno=<%=pageno - 1%>">上一页</a> | <a
href="articleflat.jsp?pageno=<%=pageno + 1%>">下一页</a> | <a
href="articleflat.jsp?pageno=<%=totalpage%>">最后一页</a>]</span> </span>
</td>
</tr>
</tbody>
<tr valign="top">
<td width="99%">
<div class="jive-thread-list">
<div class="jive-table">
<table summary="List of threads" cellpadding="0" cellspacing="0"
width="100%">
<thead>
<tr>
<th class="jive-first" colspan="3">
主题
</th>
<th class="jive-author">
<nobr>
作者
</nobr>
</th>
<th class="jive-view-count">
<nobr>
浏览
</nobr>
</th>
<th class="jive-msg-count" nowrap="nowrap">
回复
</th>
<th class="jive-last" nowrap="nowrap">
最新帖子
</th>
</tr>
</thead>
<tbody>
<%
int lineno = 0;
for (Iterator<Article> it = articles.iterator(); it.hasNext();) {
Article a = it.next();
//String prestr="";
String classstr = lineno % 2 == 0 ? "jive-even" : "jive-odd";
%>
<tr class="<%=classstr%>">
<td class="jive-first" nowrap="nowrap" width="1%">
<div class="jive-bullet">
<img src="images/read-16x16.gif" alt="已读" border="0"
height="16" width="16">
<!-- div-->
</div>
<%
String url = request.getScheme() + "://"
+ request.getServerName() + ":"
+ request.getServerPort();
url += request.getContextPath();
url += request.getServletPath();
url += "?" + request.getQueryString();
//或者用下面的方法
//String url=request.getRequestDispatcher()+"?"+request.getQueryString();
%>
</td>
<td nowrap="nowrap" width="2%">
<br>
<%
if (islogined) {
%>
<a
href="delete.jsp?id=<%=a.getId()%>&isleaf=<%=a.isIsleaf()%>&pid=<%=a.getPid()%>&from=<%=url%>">
删除</a>
<%
}
%>
</td>
<td nowrap="nowrap" width="2%"><br>
<%
if (islogined) {
%>
<a href="update.jsp?id=<%=a.getId()%>">更新</a>
<%
}
%>
</td>
<td class="jive-thread-name" width="94%">
<a id="jive-thread-1"
href="articleDetlflat.jsp?id=<%=a.getId()%>"><%=a.getTitle()%></a>
</td>
<td class="jive-author" nowrap="nowrap" width="1%">
<span class=""> <a
href="http://bbs.chinajavaworld.com/profile.jspa?userID=226030">weijing_007</a>
</span>
</td>
<td class="jive-view-count" width="1%">
100
</td>
<td class="jive-msg-count" width="1%">
1
</td>
<td class="jive-last" nowrap="nowrap" width="1%">
<div class="jive-last-post"><%=new java.text.SimpleDateFormat("yyyy-mm-dd hh:mm:ss")
.format(a.getPdate())%>
<br>
by:
<a
href="http://bbs.chinajavaworld.com/thread.jspa?messageID=780182#780182"
title="jingjiangjun" style="">weijing_007»</a>
</div>
</td>
</tr> <%
lineno++;
}
%>
</tbody>
</table>
</div>
</div>
<div class="jive-legend"></div>
</td>
</tr>
</table>
<br>
<br>
</div>
</body>
</html>
rs=stmt.executeQuery(sql);
int nums=rs.getInt(1);
int pagesize=3;
int pagecount=ceil(nums/pagesize);
//接收jsp页面的传值
int showpage=request.gwtParameter("showpage");
//对接到的值进行判断,确定当前页为第几页
if(showpage)
{
showpage=1;
}
if(showpage>pagecount)
{
showpage=pagecount;
}
if(showpage<1)
{
showpage=1;
}
//根据当前页和每页显示数确定当查询开始的位置
int startrow=(showpage-1)*pagesize;
//查询当前页要显示的数据的sql语句
String sql1="select * from news order by id asc limit "+startrow+","+pagesize;
……
然后通过每页显示的记录知道总页数,然后通过获取 当前页数判断是否要转到第一页和最后一页等等,然后在执行你的那个sql :select * from jlkjlk limit *,*