📄 roleinfodao.java
字号:
/**
*
*/
package cn.bway.admin.dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.*;
import cn.bway.admin.vo.RoleAndStaffVO;
import cn.bway.admin.vo.RoleInfoVO;
import cn.bway.common.BwayHibernateException;
import cn.bway.common.PlatformException;
/**
* @author Kson
*
*/
public class RoleInfoDAO {
protected final Logger log = LogManager.getLogger(getClass());
private Connection conn = null;
public RoleInfoDAO(Connection conn) {
this.conn = conn;
}
private ResultSet rs = null;
private PreparedStatement stat = null;
RightInfoDAO rightInfo = null;
/**
* ��ѯ��ɫ��Ϣ
* @param vo RoleInfoVO
* @return List
* @throws BwayHibernateException
*/
public List queryRoleInfo(RoleInfoVO vo) throws BwayHibernateException {
List resultList = new ArrayList();
RoleInfoVO resultVO = null;
try {
String strsql = "select * from roles where 1=1";
if (vo.getRoleName() != null && !vo.getRoleName().equals("")) {
strsql += " and roleName like '%" + vo.getRoleName() + "%' ";
}
strsql += " order by roleid desc";
stat = conn.prepareStatement(strsql);
rs = stat.executeQuery();
while (rs != null && rs.next()) {
resultVO = new RoleInfoVO();
resultVO.setRoleId(rs.getString("roleid"));
resultVO.setRoleName(rs.getString("rolename"));
resultVO.setDescription(rs.getString("roledesc"));
resultVO.setDelEnable(rs.getString("delenable"));
resultList.add(resultVO);
}
System.out.println(" from dao queryRoleInfo get the list: "+resultList);
} catch (SQLException ex) {
ex.printStackTrace();
log.info("��ѯ��ɫ�����쳣:" + ex.getMessage());
}
finally {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultList;
}
/**
* ��ѯ��ɫ��Ϣ����
* @param vo RoleInfoVO
* @return List
* @throws BwayHibernateException
*/
public Integer queryRoleInfoCount(RoleInfoVO vo) throws BwayHibernateException {
List resultList = new ArrayList();
RoleInfoVO resultVO = null;
int intRowsCount = 0;
try
{
String strsql = "select count(*) from roles where 1=1";
if (vo.getRoleName() != null && !vo.getRoleName().equals(""))
{
strsql += " and roleName like '%" + vo.getRoleName() + "%' ";
}
stat = conn.prepareStatement(strsql);
rs = stat.executeQuery();
while (rs != null && rs.next()) {
intRowsCount = rs.getInt(1);
}
} catch (SQLException ex)
{
log.info("��ѯ��ɫ�����쳣:" + ex.getMessage());
} finally
{
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return new Integer(intRowsCount);
}
/**
* ɾ���ɫ
* @param vo RoleInfoVO
* @throws BwayHibernateException
*/
public void deleteRoleInfo(RoleInfoVO vo) throws BwayHibernateException {
try {
String strsql = "delete roles";
if (!vo.getRoleId().equals("")) {
strsql += " where roleid = '" + vo.getRoleId() + "' ";
stat = conn.prepareStatement(strsql);
stat.executeUpdate();
}
} catch (SQLException ex) {
log.info("ɾ���ɫ�����쳣:" + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* ���½�ɫ
* @param vo RoleInfoVO
* @throws BwayHibernateException
*/
public void updateRoleInfo(RoleInfoVO vo) throws BwayHibernateException {
try {
String strsql ="update roles set rolename=?, ROLEDESC=? where roleid=?";
stat = conn.prepareStatement(strsql);
stat.setString(1, vo.getRoleName());
stat.setString(2, vo.getDescription());
stat.setInt(3, Integer.parseInt(vo.getRoleId()));
stat.execute();
} catch (SQLException ex) {
log.info("���½�ɫ�����쳣: " + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* �����ɫ����
* @param vo RoleInfoVO
* @throws BwayHibernateException
*/
public void insertRoleInfo(RoleInfoVO vo) throws BwayHibernateException {
try {
String strsql =
"insert into roles (roleid, rolename, ROLEDESC) values (?,?,?)";
stat = conn.prepareStatement(strsql);
stat.setInt(1, Integer.parseInt(vo.getRoleId()));
stat.setString(2, vo.getRoleName());
stat.setString(3, vo.getDescription());
stat.execute();
} catch (SQLException ex) {
log.info("�����ɫ�����쳣: " + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* ��ѯ��ɫ
* @param vo RoleInfoVO
* @return List
* @throws BwayHibernateException
*/
public List getRoleInfo(RoleInfoVO vo) throws BwayHibernateException {
List resultList = new ArrayList();
RoleInfoVO resultVO = null;
try {
String strsql = "select * from roles where 1=1";
if (!vo.getRoleId().equals("")) {
strsql += " and roleid = '" + vo.getRoleId() + "' ";
}
stat = conn.prepareStatement(strsql);
rs = stat.executeQuery();
while (rs != null && rs.next()) {
resultVO = new RoleInfoVO();
resultVO.setRoleId(rs.getString(1));
resultVO.setRoleName(rs.getString(2));
resultVO.setDescription(rs.getString(3));
resultList.add(resultVO);
}
} catch (SQLException ex) {
log.info("��ѯ��ɫ�����쳣: " + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultList;
}
/**
* ��ȡ����
* @return int
* @throws BwayHibernateException
*/
public int querySeq(String tmpTableName) throws BwayHibernateException {
int returnInt = 0;
String strsql = "";
try {
strsql = "update makerconfig set currentvalue = currentvalue+1 where tablename = '"+tmpTableName+"' ";
stat = conn.prepareStatement(strsql);
stat.executeUpdate();
strsql = "select currentvalue from makerconfig where tablename = '"+tmpTableName+"' ";
stat = conn.prepareStatement(strsql);
ResultSet rs = stat.executeQuery();
if (rs.next()) {
returnInt = rs.getInt("currentvalue");
}
} catch (SQLException ex) {
ex.printStackTrace();
log.info("��ȡ���в����쳣: " + ex.getMessage());
}
finally {
try {
rs.close();
stat.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -