⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rentdaoimpl.java

📁 本程序主要实现对管理系统的初步管理
💻 JAVA
字号:
package org.ads123.goodsmanagers.dao.impl;

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

import org.JavaChina.myjdbc.ConnectPool;
import org.ads123.goodsmanagers.dao.RentDao;
import org.ads123.goodsmanagers.dto.Rent;

public class RentDaoImpl implements RentDao {

	public ArrayList<Rent> findRentInfoByC_no(String C_no) {
		ArrayList<Rent> rent_list = new ArrayList<Rent>();
		Connection conn = ConnectPool.getInstance().getConnection();
		PreparedStatement pstm = null;
		ResultSet rst = null;
		String sql = "select R_no, R_date, R_time, G_name, R_use, R_nouse from rent where C_no = ?";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, C_no);
			rst = pstm.executeQuery();
			while (rst.next()) {
				String r_no = rst.getString("R_no");
				Date r_date = rst.getDate("R_date");
				int r_time = rst.getInt("R_time");
				String g_name = rst.getString("G_name");
				float r_use = rst.getFloat("R_use");
				float r_nouse = rst.getFloat("R_nouse");
				rent_list.add(new Rent(r_no, r_date, r_time, C_no, g_name, r_use,
						r_nouse));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				if(rst != null){
					rst.close();
				}
				if(pstm != null){
					pstm.close();
				}
				if(conn != null && !conn.isClosed()){
					ConnectPool.getInstance().destroyConnection(conn);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return rent_list;
	}

	public static void main(String[] args) {
		ArrayList<Rent> list1 = new RentDaoImpl().findRentInfoByC_no("10005");
		for(Rent list:list1){
			System.out.println(list.getR_no() + "  " + list.getR_date() + "  " + list.getR_time() + "  " + list.getG_name() + "  " + list.getR_use() + "  " + list.getR_nouse());
		}
	}

	public ArrayList<String> findR_noList() {
		ArrayList<String> r_no_list = new ArrayList<String>();
		
		Connection conn = ConnectPool.getInstance().getConnection();
		PreparedStatement pstm = null;
		ResultSet rst = null;
		String sql = "select R_no from rent where G_name != '空'";
		try {
			pstm = conn.prepareStatement(sql);
			rst = pstm.executeQuery();
			while (rst.next()) {
				String r_no = rst.getString("R_no");
				r_no_list.add(r_no);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				if(rst != null){
					rst.close();
				}
				if(pstm != null){
					pstm.close();
				}
				if(conn != null && !conn.isClosed()){
					ConnectPool.getInstance().destroyConnection(conn);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return r_no_list;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -