deptdco.java

来自「海鲜超市管理 登录 修改 增加 等功能jsp+servlet」· Java 代码 · 共 123 行

JAVA
123
字号
/*
 * 创建日期 2006-12-18
 * TODO 
 */
package module.dept.dco;

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

import tools.PageControl;
import conn.ConnSky;
import dto.DeptDto;
import dto.IncomeDto;


public class DeptDco {
	
	public static int sumNote;
	
	public void selectDept(List list, String curpage){
		PageControl pc = new PageControl();
		Connection conn = null;
		ResultSet rs = null;
		PreparedStatement pstmt = null;
		DeptDto dDto = null;
		String sql = "select dept_id, dept_name, dept_description from table_dept" ;

		try {
			conn = ConnSky.getConn();
			pstmt = conn.prepareStatement(sql,
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			rs = pstmt.executeQuery();
			rs.absolute(-1);
			sumNote = rs.getRow();
			pc.init(Integer.parseInt(curpage), sumNote);
			
			if (sumNote > 0) {
				if (pc.getStart() == 0) {
					rs.absolute(1);
				} else {
					rs.absolute(pc.getStart());
				}
			}
			do {
				dDto = new DeptDto();
				dDto.setName(rs.getString("dept_name"));
				dDto.setId(rs.getString("dept_id"));
				dDto.setDescription(rs.getString("dept_description"));
				list.add(dDto);
				if (!rs.next()) {
					break;
				}

			} while (rs.getRow() < pc.getEnd() + 1);
			
		} catch (Exception e) {
			e.printStackTrace();
		}		
		
		
	}
	
	public void addDept(DeptDto dto){
		Connection conn = null;
		PreparedStatement pstmt = null;
		int flag = 0;
		String sql = "insert into table_dept values (dept_seq.nextval,?,?)";
		
		try{
			conn = ConnSky.getConn();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,dto.getName());
			pstmt.setString(2,dto.getDescription());
			flag = pstmt.executeUpdate();
			conn.commit();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				pstmt.close();
				conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		
		
	}

	public void updateDept(DeptDto dto){
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		int flag = 0;
		String sql = "update table_dept set dept_name =? ,dept_description=? where dept_id =? ";
		
		try{
			conn = ConnSky.getConn();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,dto.getName());
			pstmt.setString(2,dto.getDescription());
			pstmt.setInt(3,Integer.parseInt(dto.getId()));
			flag = pstmt.executeUpdate();
			conn.commit();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				pstmt.close();
				conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	
	}	


}

⌨️ 快捷键说明

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