unitdao.java

来自「实现银行系统中某个部门的计算机设备管理、公共信息管理、权限用户管理、系统设置等,」· Java 代码 · 共 100 行

JAVA
100
字号
package com.isoftstone.banktearm1.dao;
/*
 * 07作成部门及机构
 */
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;

import com.isoftstone.banktearm1.db.DB;
import com.isoftstone.banktearm1.vo.BankTeam1UnitVo;

public class UnitDao extends com.isoftstone.banktearm1.db.DB{
	
	public ArrayList getUnit() throws SQLException, ClassNotFoundException{
		ArrayList list=new ArrayList();
		Connection con=this.getConnection();
		Statement stmt=con.createStatement();
		String sql="select * from unit";
		ResultSet rs=stmt.executeQuery(sql);
		while(rs.next()){
			int id=rs.getInt("id");
			int unitId=rs.getInt("unitId");
			String unitName=rs.getString("unitName");
			String upUnit=rs.getString("upUnit");
			String unitmemo=rs.getString("unitmemo");
			BankTeam1UnitVo btvo=new BankTeam1UnitVo(id,unitId,unitName,upUnit,unitmemo);
			list.add(btvo);
		}
		this.closs(rs,stmt,con);
		return list;
	}
	
	public void deleteUnit(int i) throws SQLException, ClassNotFoundException{
		ArrayList list=this.getUnit();
		Connection con=this.getConnection();
		Statement stmt=con.createStatement();
		String sql="delete * from unit where UnitId="+i;
		stmt.executeUpdate(sql);
		this.closs(stmt,con);
	}
	
	public void insertUnit(int id,int unitid,String unitname,String unitmemo ) throws SQLException, ClassNotFoundException{
		DB db=new DB();
		Connection con=db.getConnection();
		Statement stmt=con.createStatement();
		String sql1="insert into unit values("+id+","+unitid+",'"+unitname+"',"+0+",'"+unitmemo+"')";
		stmt.executeUpdate(sql1);
		this.closs(stmt,con);
	}
	
	public void updateUnit(String unitname,String unitmemo,int unitid) throws SQLException, ClassNotFoundException{
		DB db=new DB();
		Connection con=db.getConnection();
		Statement stmt=con.createStatement();
		String sql1="update unit Set UnitName='"+unitname+"'"+",Unitmemo='"+unitmemo+"' where UnitId="+unitid;
		stmt.executeUpdate(sql1);
		db.closs(stmt,con);
	}
	
	public BankTeam1UnitVo getRow(int i) throws SQLException, ClassNotFoundException{
		ArrayList list=this.getUnit();
		Connection con=this.getConnection();
		Statement stmt=con.createStatement();
		String sql="select * from unit where UnitId="+i;
		ResultSet rs=stmt.executeQuery(sql);
		BankTeam1UnitVo btvo=null;
		if(rs.next()){
			int id=rs.getInt("id");
			int unitId=rs.getInt("unitId");
			String unitName=rs.getString("unitName");
			String upUnit=rs.getString("upUnit");
			String unitmemo=rs.getString("unitmemo");
			btvo=new BankTeam1UnitVo(id,unitId,unitName,upUnit,unitmemo);
		}
		this.closs(rs,stmt,con);
		return btvo;
	}
	
	public int getMax(String s) throws SQLException, ClassNotFoundException{
		int i=0;
		Connection con=this.getConnection();
		Statement stmt=con.createStatement();
		String sql="select max("+s+")  from unit";
		ResultSet rs=stmt.executeQuery(sql);
		if(rs.next()){
			i=rs.getInt(1);
		}
		return i;
	}
	
	public void getDelflag(String []delflag) throws NumberFormatException, SQLException, ClassNotFoundException{
		for(int i=0;i<delflag.length;i++)
			this.deleteUnit(Integer.parseInt(delflag[i]));
	}

}

⌨️ 快捷键说明

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