Code example for Connection

Methods: close, prepareStatement

0
 
        try { 
            checkSystemVm(conn);
        } finally { 
            try { 
                conn.close();
            } catch (SQLException e) {
            } 
        } 
    } 
 
    protected void checkSystemVm(Connection conn) throws SQLException {
        PreparedStatement pstmt;
 
        pstmt = conn
                .prepareStatement("SELECT version FROM `cloud`.`version` ORDER BY id DESC LIMIT 1");
        ResultSet rs = pstmt.executeQuery();
        assert rs.next() : "No version selected";
        assert rs.getString(1).equals("3.0.0") : "VERSION stored is not 3.0.0: "
                + rs.getString(1);
        rs.close();
        pstmt.close();
 
        pstmt = conn.prepareStatement("select id from vm_template where name='systemvm-xenserver-3.0.0' and removed is null");
        rs = pstmt.executeQuery();
        long templateId1 = rs.getLong(1);
        rs.close();
        pstmt.close();
         
        pstmt = conn.prepareStatement("select distinct(vm_template_id) from vm_instance where type <> 'USER' and hypervisor_type = 'XenServer'");
        rs = pstmt.executeQuery();
        long templateId = rs.getLong(1);
        rs.close();
        pstmt.close();
 
        assert (templateId ==  templateId1) : "XenServer System Vms not using 3.0.0 template";
        rs.close();
        pstmt.close();
         
        pstmt = conn.prepareStatement("select id from vm_template where name='systemvm-kvm-3.0.0' and removed is null");
        rs = pstmt.executeQuery();
        long templateId3 = rs.getLong(1);
        rs.close();
        pstmt.close();
         
        pstmt = conn.prepareStatement("select distinct(vm_template_id) from vm_instance where type <> 'USER' and hypervisor_type = 'KVM'");
        rs = pstmt.executeQuery();
        long templateId4 = rs.getLong(1);
        rs.close();
        pstmt.close();