JAVA List 用法

package boda.admin;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.sql.*;

import boda.command.ConnSQL2000;

/**
 * @author dovebo
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class SystemAdmin {

 /**
  * Constructor for SystemAdmin.
  */
 public SystemAdmin() {
  super();
 }

 ConnSQL2000 conn2k = new ConnSQL2000();
 List userAllList = new ArrayList();
 String userRoleName;

 /**
  * Returns the userAllList 获得所有的用户信息.
  * @return List
  */
 public List getUserAllList() {  
  Connection conn = conn2k.getConn();
  String sql = "select * from  BODA_USER order by ID asc";        

  try {
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery(sql);

   while (rs.next()){  
   userBean usbean = new userBean(); 
   
   usbean.setID(rs.getString("ID")); 
   usbean.setUserName(rs.getString("UserName"));
   usbean.setZName(rs.getString("ZName"));
   usbean.setPassword(rs.getString("PassWord"));
   usbean.setRole_ID(rs.getString("Role_ID"));
   usbean.setTel(rs.getString("tel"));
   usbean.setSex(rs.getString("sex"));
   usbean.setAge(rs.getString("age"));
   usbean.setMemo(rs.getString("memo"));
   usbean.setRegDatetime(rs.getString("regDatetime")); 
    
   userAllList.add(usbean);
   }   

  } catch (Exception e) {
   e.printStackTrace();
  }
  
  return userAllList;
 }

 /**
  * Returns the userRoleName.
  * @return String
  */
 public String getUserRoleName() {
  return userRoleName;
 }

}




--------------------------------------------------------------------------------


package boda.admin;

/**
 * @author dovebo
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class userBean {
 
    String ID; //ID 标示
 String UserName; //用户名  (唯一)
 String ZName; //真名
 String Password; //密码
 String role_ID; //角色ID
 String Sex; //性别
 String Tel; //电话
 String age; //年龄
 String memo; //备注
 String regDatetime;//注册时间

 /**
  * Returns the age.
  * @return String
  */
 public String getAge() {
  return age;
 }

 /**
  * Returns the memo.
  * @return String
  */
 public String getMemo() {
  return memo;
 }

 /**
  * Returns the password.
  * @return String
  */
 public String getPassword() {
  return Password;
 }

 /**
  * Returns the regDatetime.
  * @return String
  */
 public String getRegDatetime() {
  return regDatetime;
 }

 /**
  * Returns the role_ID.
  * @return String
  */
 public String getRole_ID() {
  return role_ID;
 }

 /**
  * Returns the sex.
  * @return String
  */
 public String getSex() {
  return Sex;
 }

 /**
  * Returns the tel.
  * @return String
  */
 public String getTel() {
  return Tel;
 }

 /**
  * Returns the userName.
  * @return String
  */
 public String getUserName() {
  return UserName;
 }

 /**
  * Returns the zName.
  * @return String
  */
 public String getZName() {
  return ZName;
 }

 /**
  * Sets the age.
  * @param age The age to set
  */
 public void setAge(String age) {
  this.age = age;
 }

 /**
  * Sets the memo.
  * @param memo The memo to set
  */
 public void setMemo(String memo) {
  this.memo = memo;
 }

 /**
  * Sets the password.
  * @param password The password to set
  */
 public void setPassword(String password) {
  Password = password;
 }

 /**
  * Sets the regDatetime.
  * @param regDatetime The regDatetime to set
  */
 public void setRegDatetime(String regDatetime) {
  this.regDatetime = regDatetime;
 }

 /**
  * Sets the role_ID.
  * @param role_ID The role_ID to set
  */
 public void setRole_ID(String role_ID) {
  this.role_ID = role_ID;
 }

 /**
  * Sets the sex.
  * @param sex The sex to set
  */
 public void setSex(String sex) {
  Sex = sex;
 }

 /**
  * Sets the tel.
  * @param tel The tel to set
  */
 public void setTel(String tel) {
  Tel = tel;
 }

 /**
  * Sets the userName.
  * @param userName The userName to set
  */
 public void setUserName(String userName) {
  UserName = userName;
 }

 /**
  * Sets the zName.
  * @param zName The zName to set
  */
 public void setZName(String zName) {
  ZName = zName;
 }

 /**
  * Returns the iD.
  * @return String
  */
 public String getID() {
  return ID;
 }

 /**
  * Sets the iD.
  * @param iD The iD to set
  */
 public void setID(String iD) {
  ID = iD;
 }

}



--------------------------------------------------------------------------------


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@ page import="boda.command.ConnSQL2000"%>
<%@ page import="boda.admin.userBean"%>
<%@ page import="boda.admin.SystemAdmin"%>
<%@ page import="java.util.*"%>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>index.jsp</TITLE>
</HEAD>
<BODY>
<%
userBean ub = new userBean();
SystemAdmin sa = new SystemAdmin();
List uslist = new ArrayList();
     uslist = sa.getUserAllList();

  /* 
//方法一   
 Iterator iterator = uslist.iterator(); 
 while(iterator.hasNext()){ 
 ub = (userBean)iterator.next(); 
 out.print(ub.getUserName());
 out.print("<br>"); 
 }
  */

//方法二 
for(int i=0;i<uslist.size();i++){
 ub =(userBean)uslist.get(i); 
 out.print(ub.getUserName());
 out.print("<br>");
 }

%>
</BODY>
</HTML>





文章来自: 本站原创
引用通告地址: http://www.is21.cn/trackback.asp?tbID=130
Tags:
评论: 0 | 引用: 0 | 查看次数: 4447
发表评论
你没有权限发表留言!