从数据库提取显示页面

package com.ssk.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.ssk.beans.Tongxinlu;

public class TongxinluDaoImpl implements TongxinluDao {
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	public ArrayList<Tongxinlu> al = new ArrayList<Tongxinlu>();// 储存

	// 查找通信录列表
	public ArrayList xianshiTongxinluDao(Tongxinlu tongxinlu) {
		Statement pstmt = null;
		JDBCUtilss jdbcutils2 = new JDBCUtilsMysql();
		conn = jdbcutils2.getConn();
		// /String sql =
		// "select top "+pageSize+" * from tongxinlu where name not in (select top "+(pageNow-1)*pageSize+"name from tongxinlu)";
		// String sql
		// ="select * from tongxinlu order by id limit "+(pageNow*pageSize-pageSize)+","+pageSize;
		String sql = "select * from tongxinlu;";
		try {
			pstmt = conn.createStatement();
			rs = pstmt.executeQuery(sql);
			System.out.println("查找数据库表通信录操作完毕");
			while (rs.next()) {
				Tongxinlu tongxinlu2 = new Tongxinlu();
				tongxinlu2.setId(rs.getInt(1));
				tongxinlu2.setName(rs.getString(2));
				tongxinlu2.setTelephone(rs.getString(3));
				tongxinlu2.setAddress(rs.getString(4));
				tongxinlu2.setEmail(rs.getString(5));
				tongxinlu2.setQq(rs.getString(6));
				al.add(tongxinlu2);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			JDBCUtilsMysql.freeConn(rs, pstmt, conn);
		}
		return al;
	}

<%@ page language="java" import="java.util.*,com.ssk.action.*" pageEncoding="GB18030"%><%@taglib prefix="s" uri="/struts-tags"%><%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>登录前主页</title></head><body bgcolor="#9966FF" ><div align="center"><label> <strong><font size="+5"><fontcolor="#FF0066">通信录</font> </font> </strong><br /> </label><hr><a href="login.jsp">登录</a><a href="register.jsp">注册</a><br /><s:form action="xianshi1" method="post" theme="simple"><s:submit value="显示" /></s:form><table border="1"><tr><th>编号</th><th>姓名</th><th>电话</th><th>地址</th><th>邮箱</th><th>qq</th></tr><tr><s:iterator value="tongxinlus"><tr><td><s:property value="id" /></td><td><s:property value="name" /></td><td><s:property value="telephone" /></td><td><s:property value="address" /></td><td><s:property value="email" /></td><td><s:property value="qq" /></td></tr></s:iterator></tr></table></div><!-- <s:url id="url_pre" value="xianshi.action"><s:param name="pageNow" value="pageNow-1"></s:param></s:url><s:url id="url_next" value="xianshi.action"><s:param name="pageNow" value="pageNow+1"></s:param></s:url><s:a href="%{url_pre}" mce_href="%{url_pre}">上一页</s:a><s:iterator value="tongxunlus" status="status"><s:url id="url" value="xianshi.action"><s:param name="pageNow" value="pageNow" /></s:url></s:iterator><s:a href="%{url_next}" mce_href="%{url_next}">下一页</s:a>--></body></html>


你可能感兴趣的:(数据库)