|
//db.jsp
<%@ page language="java" import="java.util.*,java.sql.*,com.abin.db.connection.*,java.text.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>DIV+CSS</title>
</head>
<body>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String sql=null;
int pagesize=3;
int pagenum=1;
int endpage;
int startPage=1;
if(request.getParameter("pageno")!=null){
pagenum=Integer.parseInt(request.getParameter("pageno"));
}
startPage=(pagenum-1)*pagesize+1;
endpage=(startPage+pagesize);
try{
String driver="com.ibm.db2.jcc.DB2Driver";
String url="jdbc:db2://localhost:50000/lee";
String username="acer";
String password="abin";
Class.forName(driver).newInstance();
conn=DriverManager.getConnection(url,username,password);
sql="select * from (select username,age,rownumber() over(order by id desc) as rowid from lee ) a where a.rowid>="+startPage+" and a.rowid<"+endpage+"";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
out.println("<table border=2>");
out.println("<tr>");
out.println("<th width=200>"+"username"+"</th>");
out.println("<th width=200>"+"age"+"</th>");
out.println("</tr>");
while(rs.next()){
out.println("<tr>");
out.println("<td>"+rs.getString("username")+"</td>");
out.println("<td>"+rs.getInt("age")+"</td>");
out.println("</tr>");
}
out.println("</table>");
}catch(Exception e){
e.printStackTrace();
}finally{
if(null!=conn){
conn.close();
}
if(null!=stmt){
stmt.close();
}
if(null!=rs){
rs.close();
}
}
int pagecurrent=pagenum-1;
int pagenext=pagenum+1;
out.println("<a href='db.jsp?pageno="+pagecurrent+"'>"+"上一页"+"</a>");
out.println("<a href='db.jsp?pageno="+pagenext+"'>"+"下一页"+"</a>");
out.println("<br/>");
Calendar cal=Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
String show=sdf.format(cal.getTime());
out.println(show);
%>
<br/>
<a href="add.jsp">新增</a>
</body>
</html> |
|
|