.#getnames.java.1.1
来自「实现办公自动化系统」· 1 代码 · 共 102 行
1
102 行
/**
* 根据表中的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 + =
减小字号Ctrl + -
显示快捷键?