Example usage for java.sql ResultSet getDate

List of usage examples for java.sql ResultSet getDate

Introduction

In this page you can find the example usage for java.sql ResultSet getDate.

Prototype

java.sql.Date getDate(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Date object in the Java programming language.

Usage

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

private void assertWrongValueFormatColumn(final ResultSet rs) throws Exception {
    assertFalse(rs.getBoolean(2));//from   w  w  w . ja  va  2s. com
    assertFalse(rs.getBoolean("ename"));

    try {
        rs.getShort(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(2, Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate("ename", Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(2, Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime("ename", Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(2, Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp("ename", Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream("ename");
        fail();
    } catch (SQLException ignore) {
    }

}

From source file:edu.ku.brc.specify.web.SpecifyExplorer.java

/**
 * @param response// w w w  .ja va2s .co  m
 */
protected void generateCEChartOld(final HttpServletRequest request, final HttpServletResponse response) {
    String type = request.getParameter("type");

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

    Hashtable<String, NameId> alphaHash = new Hashtable<String, NameId>();
    Vector<NameId> alphaList = null;

    Connection connection = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        connection = DBConnection.getInstance().createConnection();
        stmt = connection.createStatement();
        rs = stmt.executeQuery("select startDate from collectingevent where startDate is not null");

        while (rs.next()) {
            Date date = rs.getDate(1);
            String dateStr = sdf.format(date);

            int year = Integer.parseInt(dateStr);

            int decade = (year / 10) * 10;
            dateStr = Integer.toString(decade);

            NameId nis = alphaHash.get(dateStr);
            if (nis == null) {
                nis = new NameId(dateStr, 0);
                alphaHash.put(dateStr, nis);
            }
            nis.add();
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    alphaList = new Vector<NameId>(alphaHash.values());
    Collections.sort(alphaList);
    createChart(response, type, alphaList, "Collecting Events By Decade", "Decades",
            "Number of Collecting Events");
}

From source file:mom.trd.opentheso.bdd.helper.RelationsHelper.java

/**
 * Cette fonction permet de rcuprer la liste de l'historique des relations
 * d'un concept  une date prcise d'un concept
 *
 * @param ds/*from   w ww  .  ja  v a2  s. c om*/
 * @param idConcept
 * @param idThesaurus
 * @param date
 * @param lang
 * @return Objet class Concept
 */
public ArrayList<Relation> getRelationHistoriqueFromDate(HikariDataSource ds, String idConcept,
        String idThesaurus, Date date, String lang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<Relation> listRel = null;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select lexical_value, id_concept2, role, action, hierarchical_relationship_historique.modified, username "
                        + "from hierarchical_relationship_historique, users, preferred_term, term"
                        + " where hierarchical_relationship_historique.id_thesaurus = '" + idThesaurus + "'"
                        + " and hierarchical_relationship_historique.id_concept1=preferred_term.id_concept"
                        + " and preferred_term.id_term=term.id_term" + " and term.lang='" + lang + "'"
                        + " and term.id_thesaurus='" + idThesaurus + "'" + " and ( id_concept1 = '" + idConcept
                        + "'" + " or id_concept2 = '" + idConcept + "' )"
                        + " and hierarchical_relationship_historique.id_user=users.id_user"
                        + " and hierarchical_relationship_historique.modified <= '" + date.toString()
                        + "' order by hierarchical_relationship_historique.modified ASC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    listRel = new ArrayList<>();

                    while (resultSet.next()) {
                        if (resultSet.getString("action").equals("DEL")) {
                            for (Relation rel : listRel) {
                                if (rel.getId_concept1().equals(resultSet.getString("lexical_value"))
                                        && rel.getId_concept2().equals(resultSet.getString("id_concept2"))
                                        && rel.getAction().equals("ADD")
                                        && rel.getId_relation().equals(resultSet.getString("role"))) {
                                    listRel.remove(rel);
                                    break;
                                }
                            }
                        } else {
                            Relation r = new Relation();
                            r.setId_relation(resultSet.getString("role"));
                            r.setId_concept1(resultSet.getString("lexical_value"));
                            r.setId_concept2(resultSet.getString("id_concept2"));
                            r.setModified(resultSet.getDate("modified"));
                            r.setIdUser(resultSet.getString("username"));
                            r.setAction(resultSet.getString("action"));
                            r.setId_thesaurus(idThesaurus);
                            listRel.add(r);
                        }

                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting date relation historique of Concept : " + idConcept, sqle);
    }
    return listRel;
}

From source file:mom.trd.opentheso.bdd.helper.TermHelper.java

/**
 * Cette fonction permet de rcuprer un Term par son id et son thsaurus et
 * sa langue sous forme de classe Term (sans les relations)
 *
 * @param ds/*  w  w  w . ja v  a 2s . c o  m*/
 * @param idConcept
 * @param idThesaurus
 * @param idLang
 * @return Objet class Concept
 */
public Term getThisTerm(HikariDataSource ds, String idConcept, String idThesaurus, String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    Term term = null;

    if (isTraductionExistOfConcept(ds, idConcept, idThesaurus, idLang)) {
        try {
            // Get connection from pool
            conn = ds.getConnection();
            try {
                stmt = conn.createStatement();
                try {
                    String query = "SELECT term.* FROM term, preferred_term"
                            + " WHERE preferred_term.id_term = term.id_term"
                            + " and preferred_term.id_thesaurus = term.id_thesaurus"
                            + " and preferred_term.id_concept ='" + idConcept + "'" + " and term.lang = '"
                            + idLang + "'" + " and term.id_thesaurus = '" + idThesaurus + "'"
                            + " order by lexical_value DESC";

                    /* query = "select * from term where id_concept = '"
                     + idConcept + "'"
                     + " and id_thesaurus = '" + idThesaurus + "'"
                     + " and lang = '" + idLang + "'"
                     + " and prefered = true";*/
                    stmt.executeQuery(query);
                    resultSet = stmt.getResultSet();
                    if (resultSet != null) {
                        resultSet.next();
                        term = new Term();
                        term.setId_term(resultSet.getString("id_term"));
                        term.setLexical_value(resultSet.getString("lexical_value"));
                        term.setLang(idLang);
                        term.setId_thesaurus(idThesaurus);
                        term.setCreated(resultSet.getDate("created"));
                        term.setModified(resultSet.getDate("modified"));
                        term.setSource(resultSet.getString("source"));
                        term.setStatus(resultSet.getString("status"));
                        term.setContributor(resultSet.getInt("contributor"));
                        term.setCreator(resultSet.getInt("creator"));
                    }

                } finally {
                    stmt.close();
                }
            } finally {
                conn.close();
            }
        } catch (SQLException sqle) {
            // Log exception
            log.error("Error while getting Concept : " + idConcept, sqle);
        }
    } else {
        try {
            // Get connection from pool
            conn = ds.getConnection();
            try {
                stmt = conn.createStatement();
                try {
                    String query = "select * from concept where id_concept = '" + idConcept + "'"
                            + " and id_thesaurus = '" + idThesaurus + "'";

                    stmt.executeQuery(query);
                    resultSet = stmt.getResultSet();
                    if (resultSet.next()) {
                        term = new Term();
                        term.setId_term("");
                        term.setLexical_value("");
                        term.setLang(idLang);
                        term.setId_thesaurus(idThesaurus);
                        term.setCreated(resultSet.getDate("created"));
                        term.setModified(resultSet.getDate("modified"));
                        term.setStatus(resultSet.getString("status"));
                    }

                } finally {
                    stmt.close();
                }
            } finally {
                conn.close();
            }
        } catch (SQLException sqle) {
            // Log exception
            log.error("Error while getting Concept : " + idConcept, sqle);
        }

    }

    return term;
}

From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private PostgresDocument createEmptyDocument(final Connection conn, final String table, final String name,
        final String db) throws BackendException {
    Statement st = null;//from   ww w.ja  v a 2  s  .c o m
    Statement st2 = null;
    ResultSet rs = null;
    ResultSet rs2 = null;
    PostgresDocument doc = new PostgresDocument();
    doc.setTable(this.getSchemaName(table, db) + "." + this.getPlainTableName(table));
    doc.setDatabase(db);
    doc.setName(name);
    try {
        String schema = this.getSchemaName(table, db);
        String plainTable = this.getPlainTableName(table);
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

        StringBuilder sb = new StringBuilder("");
        sb.append("select c.column_name, c.column_default, c.data_type, ccu.table_name, ccu.column_name");
        sb.append("  from information_schema.columns c");
        sb.append("  left join information_schema.key_column_usage kcu");
        sb.append("    on kcu.table_schema = c.table_schema and kcu.table_name = c.table_name");
        sb.append("     and kcu.column_name = c.column_name");
        sb.append("  left join information_schema.table_constraints tc");
        sb.append("    on tc.constraint_type='FOREIGN KEY' and tc.table_schema = c.table_schema");
        sb.append("     and tc.table_name = c.table_name and tc.constraint_name = kcu.constraint_name");
        sb.append("  left join information_schema.constraint_column_usage ccu");
        sb.append(
                "    on ccu.constraint_schema = tc.constraint_schema and ccu.constraint_name = tc.constraint_name");
        sb.append("  where c.table_schema='%s' and c.table_name='%s'");
        sb.append("  order by c.ordinal_position");
        String queryString = String.format(sb.toString().replaceAll("[ ]+", " "), schema, plainTable);

        this.logString(queryString, "?");
        rs = st.executeQuery(queryString);
        if (this.getNumRows(rs) == 0) {
            throw new BackendException(String.format("Table %s.%s has no columns which is not supported.",
                    this.getSchemaName(table, db), this.getPlainTableName(table)));
        }

        String nameField = this.getNameField(conn, table, db);
        while (rs.next()) {
            String ctype = rs.getString(3);
            String cname = rs.getString(1);
            PostgresField field = null;
            if ("character varying".equals(ctype)) {
                field = new PostgresField<String>();
                field.setType(FieldType.string);
                field.setValue(rs.getString(2));
            } else if ("text".equals(ctype)) {
                field = new PostgresField<String>();
                field.setType(FieldType.text);
                field.setValue(rs.getString(2));
            } else if ("integer".equals(ctype) || "bigint".equals(ctype) || "smallint".equals(ctype)
                    || "real".equals(ctype)) {
                field = new PostgresField<Integer>();
                field.setType(FieldType.dec);
                field.setValue(rs.getInt(2));
            } else if ("numeric".equals(ctype)) {
                field = new PostgresField<Double>();
                field.setType(FieldType.num);
                field.setValue(rs.getDouble(2));
            } else if ("date".equals(ctype)) {
                field = new PostgresField<Date>();
                field.setType(FieldType.date);
                field.setValue(rs.getDate(2));
            }
            if (field != null) {
                field.setName(cname);
                field.setUsage(FieldUsage.normal);
                if (nameField.equals(cname)) {
                    field.setValue(name);
                } else if ("version".equals(cname)) {
                    field.setUsage(FieldUsage.hidden);
                }

                String foreignTable = rs.getString(4);
                String foreignColumn = rs.getString(5);
                if (!StringUtils.isEmpty(foreignTable) && !StringUtils.isEmpty(foreignColumn)) {
                    st2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                    field.setUsage(FieldUsage.fixed);
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("select distinct \"%s\" from \"%s\" order by \"%s\"");
                    String queryString2 = String.format(sb2.toString().replaceAll("[ ]+", " "), foreignColumn,
                            foreignTable, foreignColumn);
                    this.logString(queryString2, "?");
                    rs2 = st2.executeQuery(queryString2);
                    while (rs2.next()) {
                        field.getAllowedValues().add(rs2.getObject(1));
                    }
                }
                doc.addField(cname, field);
            }
        }
    } catch (SQLException e) {
        throw new BackendException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(rs2);
        DbUtils.closeQuietly(st);
        DbUtils.closeQuietly(st2);
    }
    return doc;
}

From source file:mom.trd.opentheso.bdd.helper.TermHelper.java

/**
 * Cette fonction permet de rcuprer l'historique des termes synonymes d'un terme  une date prcise
 *
 * @param ds//  w w  w. ja va2 s  . com
 * @param idTerm
 * @param idThesaurus
 * @param idLang
 * @param date
 * @return Objet class Concept
 */
public ArrayList<NodeEM> getNonPreferredTermsHistoriqueFromDate(HikariDataSource ds, String idTerm,
        String idThesaurus, String idLang, Date date) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeEM> nodeEMList = null;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT lexical_value, modified, source, status, hiden, action, username FROM non_preferred_term_historique, users"
                        + " WHERE id_term = '" + idTerm + "'" + " and id_thesaurus = '" + idThesaurus + "'"
                        + " and lang ='" + idLang + "'"
                        + " and non_preferred_term_historique.id_user=users.id_user" + " and modified <= '"
                        + date.toString() + "' order by modified, lexical_value ASC";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    nodeEMList = new ArrayList<>();
                    while (resultSet.next()) {
                        if (resultSet.getString("action").equals("DEL")) {
                            for (NodeEM nem : nodeEMList) {
                                if (nem.getLexical_value().equals(resultSet.getString("lexical_value"))
                                        && nem.getAction().equals("ADD")
                                        && nem.getStatus().equals(resultSet.getString("status"))) {
                                    nodeEMList.remove(nem);
                                    break;
                                }
                            }
                        } else {
                            NodeEM nodeEM = new NodeEM();
                            nodeEM.setLexical_value(resultSet.getString("lexical_value"));
                            nodeEM.setModified(resultSet.getDate("modified"));
                            nodeEM.setSource(resultSet.getString("source"));
                            nodeEM.setStatus(resultSet.getString("status"));
                            nodeEM.setHiden(resultSet.getBoolean("hiden"));
                            nodeEM.setAction(resultSet.getString("action"));
                            nodeEM.setIdUser(resultSet.getString("username"));
                            nodeEM.setLang(idLang);
                            nodeEMList.add(nodeEM);
                        }

                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting NonPreferedTerm date historique of Term : " + idTerm, sqle);
    }

    return nodeEMList;
}

From source file:org.apache.marmotta.kiwi.persistence.KiWiConnection.java

/**
 * Construct a KiWiTriple from the result of an SQL query. The query result is expected to contain the
 * following columns://w w w  .j a  v  a2 s . c o  m
 * <ul>
 *     <li>id: the database id of the triple (long value)</li>
 *     <li>subject: the database id of the subject (long value); the node will be loaded using the loadNodeById method</li>
 *     <li>predicate: the database id of the predicate (long value); the node will be loaded using the loadNodeById method</li>
 *     <li>object: the database id of the object (long value); the node will be loaded using the loadNodeById method</li>
 *     <li>context: the database id of the context (long value); the node will be loaded using the loadNodeById method</li>
 *     <li>creator: the database id of the creator (long value); the node will be loaded using the loadNodeById method; may be null</li>
 *     <li>deleted: a flag (boolean) indicating whether this triple has been deleted</li>
 *     <li>inferred: a flag (boolean) indicating whether this triple has been inferred by the KiWi reasoner</li>
 *     <li>createdAt: a timestamp representing the creation date of the triple</li>
 *     <li>createdAt: a timestamp representing the deletion date of the triple (null in case triple is not deleted)</li>
 * </ul>
 * The method will not change the ResultSet iterator, only read its values, so it needs to be executed for each row separately.
 *
 * @param row a database result containing the columns described above
 * @return a KiWiTriple representation of the database result
 */
protected KiWiTriple constructTripleFromDatabase(ResultSet row) throws SQLException {
    if (row.isClosed()) {
        throw new ResultInterruptedException("retrieving results has been interrupted");
    }

    // columns: id,subject,predicate,object,context,deleted,inferred,creator,createdAt,deletedAt
    //          1 ,2      ,3        ,4     ,5      ,6      ,7       ,8      ,9        ,10

    Long id = row.getLong(1);

    KiWiTriple cached = tripleCache.get(id);

    // lookup element in cache first, so we can avoid reconstructing it if it is already there
    if (cached != null) {
        return cached;
    }

    KiWiTriple result = new KiWiTriple();
    result.setId(id);

    KiWiNode[] batch = loadNodesByIds(row.getLong(2), row.getLong(3), row.getLong(4), row.getLong(5));
    result.setSubject((KiWiResource) batch[0]);
    result.setPredicate((KiWiUriResource) batch[1]);
    result.setObject(batch[2]);
    result.setContext((KiWiResource) batch[3]);

    //        result.setSubject((KiWiResource)loadNodeById(row.getLong(2)));
    //        result.setPredicate((KiWiUriResource) loadNodeById(row.getLong(3)));
    //        result.setObject(loadNodeById(row.getLong(4)));
    //        result.setContext((KiWiResource) loadNodeById(row.getLong(5)));
    if (row.getLong(8) != 0) {
        result.setCreator((KiWiResource) loadNodeById(row.getLong(8)));
    }
    result.setDeleted(row.getBoolean(6));
    result.setInferred(row.getBoolean(7));
    result.setCreated(new Date(row.getTimestamp(9).getTime()));
    try {
        if (row.getDate(10) != null) {
            result.setDeletedAt(new Date(row.getTimestamp(10).getTime()));
        }
    } catch (SQLException ex) {
        // work around a MySQL problem with null dates
        // (see http://stackoverflow.com/questions/782823/handling-datetime-values-0000-00-00-000000-in-jdbc)
    }

    cacheTriple(result);

    return result;
}

From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java

/**
 * Gets the total api traffic for histogram.
 *
 * @param fromDate the from date/*from ww w.  j a va2  s  .c om*/
 * @param toDate the to date
 * @param subscriber the subscriber
 * @param operator the operator
 * @param applicationId the application id
 * @param api the api
 * @return the total api traffic for histogram
 * @throws Exception the exception
 */
public List<String[]> getTotalAPITrafficForHistogram(String fromDate, String toDate, String subscriber,
        String operator, int applicationId, String api) throws Exception {
    String consumerKey = null;
    if (subscriber.equals("__ALL__")) {
        subscriber = "%";
    }
    if (operator.equals("__ALL__")) {
        operator = "%";
    }
    if (applicationId == 0) {
        consumerKey = "%";
    } else {
        consumerKey = apiManagerDAO.getConsumerKeyByApplication(applicationId);
    }
    if (api.equals("__ALL__")) {
        api = "%";
    }

    if (consumerKey == null) {
        return null;
    }
    List<String[]> api_list = apiManagerDAO.getAPIListForAPITrafficHistogram(fromDate, toDate, api);

    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet results = null;
    StringBuilder sql = new StringBuilder();

    sql.append("select api,date(time) as date, sum(response_count) hits from ")
            .append(ReportingTable.SB_API_RESPONSE_SUMMARY.getTObject())
            .append(" where DATE(time) between STR_TO_DATE(?,'%Y-%m-%d') and STR_TO_DATE(?,'%Y-%m-%d') AND operatorId LIKE ? AND userId LIKE ? AND API LIKE ? AND consumerKey LIKE ? ")
            .append("group by api, date");

    List<String[]> api_request = new ArrayList<String[]>();

    try {
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB);
        ps = conn.prepareStatement(sql.toString());
        ps.setString(1, fromDate);
        ps.setString(2, toDate);
        ps.setString(3, operator);
        ps.setString(4, subscriber);
        ps.setString(5, api);
        ps.setString(6, consumerKey);

        log.debug("getTotalTrafficForHistogram");
        results = ps.executeQuery();
        while (results.next()) {
            String[] temp = { results.getString(1), results.getDate(2).toString(), results.getString(3) };
            api_request.add(temp);
        }

        for (int i = 0; i < api_request.size(); i++) {
            String apiRequestNameNDate = api_request.get(i)[0].toString() + "_"
                    + api_request.get(i)[1].toString();
            for (int j = 0; j < api_list.size(); j++) {
                String apiNameNDate = api_list.get(j)[0].toString() + "_" + api_list.get(j)[1].toString();
                if (apiRequestNameNDate.equals(apiNameNDate)) {
                    api_list.get(j)[2] = api_request.get(i)[2];
                }
            }
        }

    } catch (Exception e) {
        handleException("getTotalAPITrafficForHistogram", e);
    } finally {
        DbUtils.closeAllConnections(ps, conn, results);
    }
    return api_list;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer la date de modificatin du Concept
 *
 * @param ds//  w ww.j  a v  a2 s.  c om
 * @param idConcept
 * @param idThesaurus
 * @return Objet class Concept
 */
public Date getModifiedDateOfConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    Date date = null;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select modified from concept where id_thesaurus = '" + idThesaurus + "'"
                        + " and id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                if (resultSet.getRow() != 0) {
                    date = resultSet.getDate("modified");
                }
                resultSet.close();

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting modified date of Concept : " + idConcept, sqle);
    }
    return date;
}

From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java

/**
 * Gets the all response times for all ap is.
 *
 * @param operator the operator/*from w w  w.  j  av  a2s.  co m*/
 * @param userId the user id
 * @param fromDate the from date
 * @param toDate the to date
 * @param timeRange the time range
 * @return the all response times for all ap is
 * @throws Exception the exception
 */
public List<APIResponseDTO> getAllResponseTimesForAllAPIs(String operator, String userId, String fromDate,
        String toDate, String timeRange) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("getAllResponseTimesForAllAPIs() for  Operator " + operator + " Subscriber " + userId
                + " betweeen " + fromDate + " to " + toDate);
    }

    if (operator.contains("__ALL__")) {
        operator = "%";
    }

    if (userId.contains("__ALL__")) {
        userId = "%";
    }

    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet results = null;

    StringBuilder sql = new StringBuilder();

    sql.append(
            "SELECT SUM(response_count) as sumCount, SUM(serviceTime) as sumServiceTime, STR_TO_DATE(time,'%Y-%m-%d') as date FROM ")
            .append(ReportingTable.SB_API_RESPONSE_SUMMARY)
            .append(" WHERE (time BETWEEN ? AND ?) AND operatorId LIKE ? AND userId LIKE ? GROUP BY date;");

    List<APIResponseDTO> responseTimes = new ArrayList<APIResponseDTO>();
    try {
        connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB);
        ps = connection.prepareStatement(sql.toString());
        ps.setString(1, fromDate + " 00:00:00");
        ps.setString(2, toDate + " 23:59:59");
        ps.setString(3, operator);
        ps.setString(4, userId);
        results = ps.executeQuery();
        while (results.next()) {
            APIResponseDTO resp = new APIResponseDTO();
            resp.setResponseCount(results.getInt("sumCount"));
            resp.setServiceTime(results.getInt("sumServiceTime"));
            resp.setDate(results.getDate("date"));

            responseTimes.add(resp);
        }
    } catch (Exception e) {
        handleException("getAllResponseTimesForAllAPIs", e);
    } finally {
        DbUtils.closeAllConnections(ps, connection, results);
    }
    return responseTimes;
}