Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:hao";
try
{
Connection conn =
DriverManager.getConnection(url,"carer", "carer");
conn.setAutoCommit(false);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);//可滚动查询数据的结果集
request.setCharacterEncoding("GB2312");
rs = stmt.executeQuery("select * from car") ;
rs.last(); //让游标到表中的最后一行
int rowCount = rs.getRow(); //获取记录总数.
pageCount = (rowCount % pageSize == 0) ? (rowCount / pageSize ) : (rowCount / pageSize +1);
int showPage = 1;//当前页
//取得用户所指定的页
String goToPage = request.getParameter("showPage");
if (goToPage == null){
goToPage = "1";
}
//转换成整形
try{
showPage = Integer.parseInt(goToPage);
}
catch (NumberFormatException ex){
showPage = 1;
}
//当前页小于等于第一页则按第一页算 如果 当前页大于等于总页数则为最后页
if(showPage <=1){
showPage = 1;
}
else if(showPage >= pageCount){
showPage = pageCount;
}
//游标的位置 (当前页 - 1) * 页面大小 + 1
int posion = (showPage -1 ) * pageSize + 1;
//设置游标的位置
rs.absolute(posion);
%>
<table border="1" align="center">
<tr>
<td width="160">车牌号</td>
<td width="160">车型</td>
<td width="160">车主</td>
<td width="160">颜色</td>
<td width="160">注册时间</td>
<td width="160">产地</td>
</tr>
</table>
<%
int i =0;
//循环显示表中的数据 pageSize(每页所显示的记录)
//rs.isAfterLast() 游标是否在最后一行之后说明后面已经没记录
while(i<pageSize && !rs.isAfterLast()){
%>
<table border="1" align="center">
<col width="160px"/><col width="160px"/><col width="160px"/><col width="160px"/>
<tr>
<td width="160"><%=rs.getString("car_id")%></td>
<td width="160"><%=rs.getString("car_type")%></td>
<td width="160"><%=rs.getString("car_owner")%></td>
<td width="160"><%=rs.getString("car_color")%></td>
<td width="160"><%=rs.getDate("reg_time")%></td>
<td width="160"><%=rs.getString("car_area")%></td>
</tr>
<%rs.next();i++;}%>
</table>
<form action="" method="get">
<table border="1" align="center">
<tr>
<td>当前第<%=showPage%>页</td>
<td>共<%=pageCount%>页</td>
<td>
<a href="car_info.jsp?showPage=1">首页</a>
<a href="car_info.jsp?showPage=<%=showPage-1%>">上一页</a>
<a href="car_info.jsp?showPage=<%=showPage+1%>">下一页</a>
<a href="car_info.jsp?showPage=<%=pageCount%>">尾页</a>
</td>
<td> 共<%=rowCount%>条记录 </td>
<td>转到
<input type="text" name="showPage" size="4"/>
<input type="submit" name="go" value="提交"/>
</td>
</tr>
</table>
</form>
<%
stmt.close();
conn.close() ;
}
catch(Exception e)
{
out.println(e) ;
}
%>
String url = "jdbc:oracle:thin:@localhost:1521:hao";
try
{
Connection conn =
DriverManager.getConnection(url,"carer", "carer");
conn.setAutoCommit(false);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);//可滚动查询数据的结果集
request.setCharacterEncoding("GB2312");
rs = stmt.executeQuery("select * from car") ;
rs.last(); //让游标到表中的最后一行
int rowCount = rs.getRow(); //获取记录总数.
pageCount = (rowCount % pageSize == 0) ? (rowCount / pageSize ) : (rowCount / pageSize +1);
int showPage = 1;//当前页
//取得用户所指定的页
String goToPage = request.getParameter("showPage");
if (goToPage == null){
goToPage = "1";
}
//转换成整形
try{
showPage = Integer.parseInt(goToPage);
}
catch (NumberFormatException ex){
showPage = 1;
}
//当前页小于等于第一页则按第一页算 如果 当前页大于等于总页数则为最后页
if(showPage <=1){
showPage = 1;
}
else if(showPage >= pageCount){
showPage = pageCount;
}
//游标的位置 (当前页 - 1) * 页面大小 + 1
int posion = (showPage -1 ) * pageSize + 1;
//设置游标的位置
rs.absolute(posion);
%>
<table border="1" align="center">
<tr>
<td width="160">车牌号</td>
<td width="160">车型</td>
<td width="160">车主</td>
<td width="160">颜色</td>
<td width="160">注册时间</td>
<td width="160">产地</td>
</tr>
</table>
<%
int i =0;
//循环显示表中的数据 pageSize(每页所显示的记录)
//rs.isAfterLast() 游标是否在最后一行之后说明后面已经没记录
while(i<pageSize && !rs.isAfterLast()){
%>
<table border="1" align="center">
<col width="160px"/><col width="160px"/><col width="160px"/><col width="160px"/>
<tr>
<td width="160"><%=rs.getString("car_id")%></td>
<td width="160"><%=rs.getString("car_type")%></td>
<td width="160"><%=rs.getString("car_owner")%></td>
<td width="160"><%=rs.getString("car_color")%></td>
<td width="160"><%=rs.getDate("reg_time")%></td>
<td width="160"><%=rs.getString("car_area")%></td>
</tr>
<%rs.next();i++;}%>
</table>
<form action="" method="get">
<table border="1" align="center">
<tr>
<td>当前第<%=showPage%>页</td>
<td>共<%=pageCount%>页</td>
<td>
<a href="car_info.jsp?showPage=1">首页</a>
<a href="car_info.jsp?showPage=<%=showPage-1%>">上一页</a>
<a href="car_info.jsp?showPage=<%=showPage+1%>">下一页</a>
<a href="car_info.jsp?showPage=<%=pageCount%>">尾页</a>
</td>
<td> 共<%=rowCount%>条记录 </td>
<td>转到
<input type="text" name="showPage" size="4"/>
<input type="submit" name="go" value="提交"/>
</td>
</tr>
</table>
</form>
<%
stmt.close();
conn.close() ;
}
catch(Exception e)
{
out.println(e) ;
}
%>