groupdao.java
来自「包括所有开发文档以及数据库文件」· Java 代码 · 共 50 行
JAVA
50 行
package dao;
import java.sql.*;
import bo.*;
public class GroupDAO {
/**
* 根据角色查询组
* @param roleId
* @return
*/
public Group selectGroupByRole(String roleId) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select * from groups where groupId in (select groupId from group_role where roleId=?);";
try {
con = DB.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setString(1, roleId);
rs = pstmt.executeQuery();
while (rs != null && rs.next()) {
// 读到数据,生成实体类
Group group = new Group();
group.setGroupId(rs.getInt("groupId"));
group.setGroupName(rs.getString("groupName"));
group.setGroupDescription(rs.getString("groupDescription"));
return group;
}
rs.close();
pstmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?