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

📄 custdao.java

📁 企业OA管理系统
💻 JAVA
字号:
package com.tingsun.oa.dao;

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

import com.tingsun.oa.po.CustInfo;

public class CustDAO extends CommDAO {
	public boolean addCustInfo(CustInfo custInfo) {
		Connection conn = this.getConn();
		PreparedStatement pst = null;
		String sql = "INSERT INTO cust_info(ID,custname,isshare,custcode)" +
				" VALUES(SEQ_CUST_INFO.nextval,?,?,?)";
//		String sql = "INSERT INTO cust_info(ID,custname,isshare,custcode)" +
//		" VALUES(SEQ_CUST_INFO.nextval,'"+custInfo.getCustName()+"',?,?)";
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, custInfo.getCustName());
			pst.setInt(2, custInfo.getShare());
			pst.setString(3, custInfo.getCustomerCode());
			pst.executeUpdate();
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}finally{
			this.closeConn(conn, pst);
		}

	}
	
	public boolean deleteCustInfo(String id) {
		Connection conn = this.getConn();
		PreparedStatement pst = null;
		String sql = "delete from cust_info where id=?";
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, id);

			pst.executeUpdate();
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}finally{
			this.closeConn(conn, pst);
		}

	}
	
		
	public List getCustList() {
		Connection conn = this.getConn();
		List list = new ArrayList();
		PreparedStatement pst = null;
		ResultSet rs = null;
		String sql = "select ID,custname,isshare,custcode from cust_info";
		try {
			pst = conn.prepareStatement(sql);
			rs = pst.executeQuery();
			while(rs.next()){
				int id = rs.getInt("ID");
				String custName = rs.getString("custname");
				int isshare = rs.getInt("isshare");
				String customerCode = rs.getString("custcode");
				CustInfo custInfo = new CustInfo();
				custInfo.setCustName(custName);
				custInfo.setCustomerCode(customerCode);
				custInfo.setId(id);
				custInfo.setShare(isshare);
				list.add(custInfo);
				
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			this.closeConn(conn, pst,rs);
		}
		return list;
	}	
	public CustInfo getCustInfo(String id) {
		Connection conn = this.getConn();
		CustInfo custInfo = new CustInfo();
		PreparedStatement pst = null;
		ResultSet rs = null;
		String sql = "select ID,custname,isshare,custcode from cust_info where id=?";
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, id);
			rs = pst.executeQuery();
			if(rs.next()){
				String custName = rs.getString("custname");
				int isshare = rs.getInt("isshare");
				String customerCode = rs.getString("custcode");
				
				custInfo.setCustName(custName);
				custInfo.setCustomerCode(customerCode);
				custInfo.setId(Integer.parseInt(id));
				custInfo.setShare(isshare);
				
				
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			this.closeConn(conn, pst,rs);
		}
		return custInfo;
	
	}
	
	public boolean updateCustInfo(CustInfo custInfo) {
		Connection conn = this.getConn();
		PreparedStatement pst = null;
		String sql = "update cust_info set custname=?,isshare=?,custcode=? where id=?" ;
//		String sql = "INSERT INTO cust_info(ID,custname,isshare,custcode)" +
//		" VALUES(SEQ_CUST_INFO.nextval,'"+custInfo.getCustName()+"',?,?)";
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, custInfo.getCustName());
			pst.setInt(2, custInfo.getShare());
			pst.setString(3, custInfo.getCustomerCode());
			pst.setInt(4, custInfo.getId());
			pst.executeUpdate();
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}finally{
			this.closeConn(conn, pst);
		}

	}	
}

⌨️ 快捷键说明

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