62,614
社区成员
发帖
与我相关
我的任务
分享
private static List<StbInfoBo> queryStbDevInfo(long offset, long limit) {
ResultSet rs = null;
PreparedStatement pstmt = null;
String sql = " SELECT * FROM (SELECT STB.ID,"
+ " STB.PARENT_RESDEV_ID," + " STB.BRAS_ID_1," + " STB.PVLAN,"
+ " rownum rwn " + " FROM STB"
+ " WHERE (STB.DEL_FLAG IS NULL OR STB.DEL_FLAG = 'U')"
+ "and stb.bras_id_1 is not null" + " AND ROWNUM <= ? )"
+ " WHERE rwn > ?";
List<StbInfoBo> stbList = new ArrayList<StbInfoBo>();
try {
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, offset + limit);
pstmt.setLong(2, offset);
rs = pstmt.executeQuery();
while (rs.next()) {
StbInfoBo stb = new StbInfoBo();
stb.setId(rs.getLong(1));
stb.setParentId(rs.getLong(2));
stb.setBrasId1(rs.getLong(3));
stb.setPvlan(rs.getLong(4));
stbList.add(stb);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtil.close(null, pstmt, rs);
}
return stbList;
}
JdbcUtil 的close访法:
[code=Java]
public static void close(Connection conn,
PreparedStatement pstmt, ResultSet rs) {
try {
if (conn != null) {
conn.close();
conn = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
public static void close(Connection conn,
PreparedStatement pstmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}