javabean和jdbc的使用实例系列(四.3)

第四步:(priShow表)

package com.sc.dao;

import java.sql.*;
import java.util.*;

import com.sc.bean.priShow;
import com.sc.tool.BaseDao;

/**
 * PriShow
 * @author ZhangShaoWen
 *
 */
public class PriShowDAO {

	//定义
	List list = new ArrayList();
	static Connection conn = null;//数据库连接对象
	static PreparedStatement ps = null;//准备执行对象
	static ResultSet rs = null;//结果集对象
	
	//得到结果集
	public List getPriShow(){
		
		List list = new ArrayList();
		String sql = "select * from priShow";
		try {
			//数据库连接
			Connection conn = BaseDao.getConnection();
			//创建PreparedStatement
			PreparedStatement ps = conn.prepareStatement(sql);
			//执行sql语句
			rs = ps.executeQuery();
			//把从数据库中得到数据 
			while(rs.next()){
				priShow prs = new priShow();
				
				prs.setId(rs.getInt("id"));
				prs.setCon(rs.getString("con"));
				prs.setNumber(rs.getString("number"));
				prs.setPsTime(rs.getString("psTime"));
				
				list.add(prs);
			}
			
			//关闭数据库资源
			BaseDao.closeAll(conn, ps, rs);
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		return list;	
	}
	
	//主函数
	public static void main(String[] args) {
		
		List list = new PriShowDAO().getPriShow();
		
		for(int i=0;i

你可能感兴趣的:(HomeWork)