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

📄 appbean.java

📁 完整的JAVA工程
💻 JAVA
字号:
package employee;

import java.util.*;
import java.sql.*;
import javax.swing.*;

/**
 * 有关职务信息数据库操作的类
 */
public class AppBean {
	String sql;
	ResultSet rs = null;

	String aAid;
	String aName;

	String colName;//列名
	String colValue;//列值
	int appId;//新职务的编号
	
	/**
	 * 添加职务信息
	 */
	public void appAdd(String aname){
		
		Database DB = new Database();
		this.aName = aname;

		if(aName == null||aName.equals("")){
			JOptionPane.showMessageDialog(null, "请输入部门名称", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else{
			sql = "insert into appointment(aname) values ('"+aName+"')";
			try{
				DB.OpenConn();
				DB.executeUpdate(sql);
				JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!");

			}
			catch(Exception e){
				JOptionPane.showMessageDialog(null, "保存失败", "错误", JOptionPane.ERROR_MESSAGE); 
			}
			finally {
				DB.closeStmt();
				DB.closeConn();
			}
		}
	}

	/**
	 * 修改职务信息
	 */
	public void appModify(String aid, String aname){
		Database DB = new Database();
		this.aAid = aid;
		this.aName = aname;

		if(aName == null||aName.equals("")){
			JOptionPane.showMessageDialog(null, "请输入职务名称", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else{
			sql = "update appointment set aname = '"+aName+"' where aid = "+Integer.parseInt(aAid)+"";
			try{
				DB.OpenConn();
				DB.executeUpdate(sql);
				JOptionPane.showMessageDialog(null,"成功修改一条新的纪录!");
			}
			catch(Exception e){
				System.out.println(e);
				JOptionPane.showMessageDialog(null, "更新失败", "错误", JOptionPane.ERROR_MESSAGE); 
			}
			finally {
				DB.closeStmt();
				DB.closeConn();
			}
		}
	}

	/**
	 * 删除职务信息
	 */
	public void appDel(String aname){
		Database DB = new Database();
		this.aName = aname;
		
		sql = "delete from appointment where aname = '"+aName+"'";
		try{
			DB.OpenConn();
			DB.executeUpdate(sql);
			JOptionPane.showMessageDialog(null,"成功删除一条新的纪录!");
		}
		catch(Exception e){
			System.out.println(e);
			JOptionPane.showMessageDialog(null, "删除失败", "错误", JOptionPane.ERROR_MESSAGE); 
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
	}
	
	/**
	 * 根据职务名称,搜索职务的相关信息
	 */
	public String[] appSearch(String aname){
		Database DB = new Database();
		this.aName = aname;
		String[] s = new String[2];

		sql = "select * from appointment where aname = '"+aName+"'";
		try{
			DB.OpenConn();
			rs = DB.executeQuery(sql);
			if(rs.next()){
				s[0] = rs.getString("aid");
			}
			else
				s = null;
		}
		catch(Exception e){
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
		return s;
	}

	/**
	 * 职务信息综合查询
	 */
	public String[][] appAllSearch(String colname,String colvalue){
		this.colName = colname;
		this.colValue = colvalue;
		
		Database DB = new Database();
		String[][] cn = null;
		int row = 0;
		int i = 0;
		
		if(colValue == null||colValue.equals("")){
			sql = "select * from appointment";
		}
		else{
			sql = "select * from appointment where "+colName+" = '"+colValue+"'";
		}

		try{
			DB.OpenConn();
			rs = DB.executeQuery(sql);
			if(rs.last()){
				row = rs.getRow();
			}
			if(row == 0){
				cn = null;
			}
			else{
				cn = new String[row][2];
				rs.first();
				rs.previous();
				while(rs.next()){
					cn[i][0] = rs.getString("aid");
					cn[i][1] = rs.getString("aname");
					i++;
				}
			}
		}
		catch(Exception e){
			System.out.println(e);
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
		return cn;
	}
	/**
	 * 获得appointment表中的所有职务名称
	 */
	public String[] getAllName(){
		
		String[] s = null;
		int row = 0;
		int i = 0;
		Database DB = new Database();

		sql = "select aname from appointment";
		try{
			DB.OpenConn();
			rs = DB.executeQuery(sql);
			if(rs.last()){
				row = rs.getRow();
			}
			if(row == 0){
				s = null;
			}
			else{
				s = new String[row];
				rs.first();
				rs.previous();
				while(rs.next()){
					s[i] = rs.getString(1);
					i++;
				}
			}
		}
		catch(Exception e){
			System.out.println(e);
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
		return s;
	}

}

⌨️ 快捷键说明

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