用的是MYsql数据库,,在JAVA里做的,用的SERVLET 现在没做分页前的流程..添加一条数据,成功后跳道查询的SERVLET然后SERVLET调用查询方法(根据条件查询
public List cjUrlsByType(String type) {
List list = new ArrayList();
String sql = "select * from urls where urlType like '%" + type
+ "%' order by urlTime desc";
try {
if (conn.isClosed()) {
Conn dbConn = new Connections();
try {
conn = dbConn.getConn();
// conn = DriverManager.getConnection("proxool.mysql");
} catch (Exception e) {
e.printStackTrace();
}
}
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
CaiJing cj = new CaiJing();
cj.setUrlId(rs.getInt("urlId"));
cj.setUrl(rs.getString("url"));
cj.setUrlType(rs.getString("urlType"));
cj.setUrlTime(rs.getString("urlTime"));
cj.setGroups(rs.getString("groups"));
list.add(cj);
}
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally {
pd.close();
}
return list;
}
)
然后成功后返回SERVLET然后转到JSP页面,带个参数,,然后在页面(
<%
if (request.getAttribute("uList") != null) {
List list = (List) request.getAttribute("uList");
for (int i = 0; i < list.size(); i++) {
CaiJing cj = (CaiJing) list.get(i);
%>
<%=cj.getUrl()%>
<%=cj.getUrlTime() %><br>
<%
}
}
%>
)
这是没做分页之前的,我想弄分页面,用SQL做的,,,,谢谢大家了,,说的详细点,带注释,,我机会都不会了,,谢谢,,一定要具体,每个步骤啥的,,,可以按上我上面那个完全改下,然后写出来
//修改以上方法 begin /////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public List cjUrlsByType(String type,int page , int row) { // page 为第几页 row 为一页取几条数据
int rowpage=row*page;
int sumRows=this.getCountcjUrlsByType(type); //获得表里的全部信息的总行数
if (sumRows > 0) { //如果有数据
if (sumRows % row > 0) {
int endPage=sumRows / row+1;
if (page==endPage) {
row = sumRows % row;
}
}
String sql = "select to (row) * from urls where urlType like '%" + type+ "%' order by urlTime desc";
//按照思路写出的sql id为排序的主键
String sql2="select top ("+row+") * from ( select top ("+row+") * from ( select top ("+rowpage+") * from ("+sql+" ) as tableInfo order by tableInfo.id ) as tableInfo ) as tableInfo order by tableInfo.id desc ";
rs = stmt.executeQuery(sql2);
//修改以上方法 end /////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
////获得表里的全部信息的总行数
public int getCountcjUrlsByType(type){
int num=0;
String sql = "select count(*) as countInfo from urls where urlType like '%" + type
+ "%' order by urlTime desc";
try {
if (conn.isClosed()) {
Conn dbConn = new Connections();
try {
conn = dbConn.getConn();
// conn = DriverManager.getConnection("proxool.mysql");
} catch (Exception e) {
e.printStackTrace();
}
}
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
num=rs.getInt(countInfo) ;
}
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally {
pd.close();
}
return num;
}