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

📄 .#getnames.java.1.1

📁 实现办公自动化系统
💻 1
字号:
/**
 * 根据表中的ID号获取相应的名称
 */

package com.oa.util;
import java.sql.*;
public class GetNames {
	public Connection con;
	public Statement stmt;
	public DBConn dbcon;
	public ResultSet rs;
	public GetNames()
	{
		
	}
	/**
	 * @根据userId号来获取用户的真实姓名
	 */
	public String getRealName(int userId)
	{
		String realName=null;
		dbcon=new DBConn();
		try
		{
			con=dbcon.getConnection();
			con.setAutoCommit(false);
			String sql="select * from tb_userinfo where userid="+userId;
			stmt=con.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
			{
				realName=rs.getString("realname");
			}
			if(con!=null){con.close();}
			if(stmt!=null){stmt.close();}
			if(rs!=null){rs.close();}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return realName;
	}

	/**
	 * @根据deptId号来获取部门名称
	 */
	public String getDeptName(int deptId)
	{
		String deptName=null;
		dbcon=new DBConn();
		try
		{
			con=dbcon.getConnection();
			con.setAutoCommit(false);
			String sql="select * from tb_department where deptid="+deptId;
			stmt=con.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
			{
				deptName=rs.getString("deptname");
			}
			if(con!=null){con.close();}
			if(stmt!=null){stmt.close();}
			if(rs!=null){rs.close();}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return deptName;
	}
	/**
	 * @根据actorId号来获取角色名称
	 */
	public String getRoleName(int actorId)
	{
		String roleName=null;
		dbcon=new DBConn();
		try
		{
			con=dbcon.getConnection();
			con.setAutoCommit(false);
			String sql="select * from tb_actors where actorid="+actorId;
			stmt=con.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
			{
				roleName=rs.getString("ACTORNAME");
			}
			if(con!=null){con.close();}
			if(stmt!=null){stmt.close();}
			if(rs!=null){rs.close();}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return roleName;
	}
}

⌨️ 快捷键说明

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