您的位置:首页 > 数据库

openfire插件开发-操作数据库

2017-03-27 09:50 204 查看
public int getCount() {

    Connection con = null;

    PreparedStatement pstmt = null;

    ResultSet rs = null;

    int count = -1;

    try {

        con = DbConnectionManager.getConnection();

        pstmt = con.prepareStatement(SQL);

        rs = pstmt.executeQuery();

        if (rs.next()) {

            count = rs.getInt(1);

        } else {

            count = 0;

        }

    } catch (SQLException sqle) {

        Log.error(sqle.getMessage(), sqle);

        return 0;

    } finally {

        DbConnectionManager.closeConnection(pstmt, con);

        try {

rs.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

    }

    return count;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  openfire java