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

📄 rolemanagedao.java

📁 使用Eclipse开发的基于struts的银行信用管理网站
💻 JAVA
字号:
package com.webwork.dao;
import java.sql.*;
import java.util.*;

import com.webwork.mapping.*;
import com.webwork.struts.form.*;
import com.webwork.dataSource.*;
import com.webwork.logic.*;
/**
 * 
 * @author keyu_Scott
 *
 */
public class RoleManageDao {
    //==========================================================
	//=向数据库插入角色信息=================================
	//==========================================================
	public int InsertRole(RoleInfoForm roleInfo)
	{
        //---------------------------变量申明---------------------------------------
		Connection connt = null;
		Statement stmt = null;
		ResultSet rs = null;
		String sql1 = "";
		String sql2 = "";
		//--------------------------------------------------------------------
		sql1 = "select ROLECODE from ROLE where ROLECODE = '" +
		roleInfo.getRolecode() +
				"'";
		sql2 = "Insert into ROLE values('" +
		StringUtil.getPrimaryKey()+
		"','" +
		roleInfo.getRolecode() +
		"','" +
		roleInfo.getRolename() +
		"','" +
		roleInfo.getRolestate() +
		"')";
		try {
			connt = MySqlSource.getConnection();
			stmt = connt.createStatement();
			rs = stmt.executeQuery(sql1);
			//----------------------------------------------------------------------
			if(rs.next())
			{
				return 1;                                                                 //编号重复
			}
			
			stmt.execute(sql2);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
			return 2;                                                                        //插入角色表失败
		}
		return 0;                                                                            //插入角色表成功
	}
    //==========================================================
	//=根据编号,名称(模糊查询)和状态查询数据库=================================
	//==========================================================
	public ArrayList QueryRole(RoleInfoForm roleInfo)
	{
        //---------------------------变量申明---------------------------------------
		Connection connt = null;
		Statement stmt = null;
		ResultSet rs = null;
		ArrayList list = new ArrayList();
		String sql = "";
		//String sql = "select * from ROLE where ROLESTATE = '"+roleInfo.getRolestate()+"'";
		//------------------Sql语句拼接-----------------------------------------
		if(!roleInfo.getRolestate().equals(""))
		{
			if(sql.equals(""))
			{
				sql = " ROLESTATE = '" +roleInfo.getRolestate()+ "'";
			}
			else
			{
				sql = sql+" and ROLESTATE = '" +roleInfo.getRolestate()+ "'";
			}
		}
		if(!roleInfo.getRolecode().equals(""))
		{
			if(sql.equals(""))
			{
				sql = " ROLECODE = '" +roleInfo.getRolecode()+ "'";
			}
			else
			{
				sql = sql+" and ROLECODE = '" +roleInfo.getRolecode()+ "'";
			}
			
		}
		if(!roleInfo.getRolename().equals(""))
		{
			if(sql.equals(""))
			{
				sql = " ROLENAME like '%" +roleInfo.getRolename()+ "%'";
			}
			else
			{
				sql = sql+" and ROLENAME like '%" +roleInfo.getRolename()+ "%'";
			}
		}
		if(sql.equals(""))
		{
			sql = "select * from ROLE";
		}
		else
			sql = "select * from ROLE where " + sql;
		//------------------------------------------------------------------------
		try {
			connt = MySqlSource.getConnection();
			stmt = connt.createStatement();
			rs = stmt.executeQuery(sql);
			
			while(rs.next())
			{
				
				RoleInfoForm role = new RoleInfoForm();
				role.setRolename(rs.getString("ROLENAME"));
				role.setRolecode(rs.getString("ROLECODE"));
				role.setRolestate(rs.getString("ROLESTATE"));
				role.setRoleSt("启用中");
				role.setOperation("禁用");
				if(role.getRolestate().equals("1"))
				{
					role.setOperation("启用");
					role.setRoleSt("禁用中");
				}
				list.add(role);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
    //==========================================================
	//=修改数据库中角色状态,根据角色编号=================================
	//==========================================================
	public int EditRoleState(String id,String state)
	{
        //---------------------------变量申明---------------------------------------
		Connection connt = null;
		Statement stmt = null;
		int rs = -1;
		String sql = "update ROLE set ROLESTATE = '"+state+"' where ROLECODE = '"+id+"'";
		try {
			connt = MySqlSource.getConnection();
			stmt = connt.createStatement();
			rs = stmt.executeUpdate(sql);
		} catch (SQLException e) {
			
			e.printStackTrace();
			return -1;                                                     //修改失败,数据库原因
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rs;
	}
}

⌨️ 快捷键说明

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