日期:2014-05-17 浏览次数:20895 次
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*"%> <%@ page import="mySql.Sqlconnection" %> <%@ page import="action.ListAction" %> <%@ page import="user.UserManager" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% Sqlconnection conn=new Sqlconnection(); List<UserManager> cag; cag=conn.list(); %> <!-- 循环遍员工姓名等 --> </body> </html>
public List<UserManager> list(){ Connection conn =this.getConnection();//使用当前连接数据库方法 List<UserManager> cag=new ArrayList<UserManager>();//UserManager为一个成员属性类getter setter try { PreparedStatement ps = conn.prepareStatement("select * from staff"); ResultSet rs =ps.executeQuery(); while(rs.next()){ UserManager u=new UserManager(); u.setStaff_ID(rs.getString("staff_ID")); u.setStaff_Name(rs.getString("staff_Name")); u.setStaff_Birth(rs.getString("staff_Birth")); u.setStaff_IDcard(rs.getString("staff_IDcard")); u.setStaff_CallNumb(rs.getString("staff_CallNumb")); cag.add(u); System.out.println(u.getStaff_Name());//这个输出就是乱码 } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } close(null, null, conn); return cag; }