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.alfaariss.oa.engine.requestor.jdbc.JDBCFactory.java

/**
 * Returns the requestor pool were the supplied request id is a part from.
 * @see com.alfaariss.oa.engine.core.requestor.factory.IRequestorPoolFactory#getRequestorPool(java.lang.String)
 *//*  w  w  w . j ava  2s.c  o m*/
@Override
public RequestorPool getRequestorPool(String sRequestor) throws RequestorException {
    JDBCRequestorPool oRequestorPool = null;
    Connection oConnection = null;
    PreparedStatement oPreparedStatement = null;
    ResultSet oResultSet = null;
    try {
        oConnection = _oDataSource.getConnection();

        oPreparedStatement = oConnection.prepareStatement(_sQuerySelectPool);
        oPreparedStatement.setString(1, sRequestor);
        oResultSet = oPreparedStatement.executeQuery();
        if (oResultSet.next()) {
            String sPoolId = oResultSet.getString(JDBCRequestorPool.COLUMN_ID);

            // Work with cache:
            if (_isCacheEnabled) {
                RequestorPoolEntry oRPE = _mRequestorPoolMap.get(sPoolId);

                if (oRPE != null) {
                    long lCachedDateLastModified = 0;
                    if (oRPE._dLastModified != null)
                        lCachedDateLastModified = oRPE._dLastModified.getTime();

                    long lRealDateLastModified = getMostRecentDate(
                            oResultSet.getTimestamp("date_last_modified"),
                            oResultSet.getTimestamp("requestor_date"));

                    if (lRealDateLastModified > 0 && (lRealDateLastModified <= lCachedDateLastModified)) {
                        // Cached version is recent; RequestorPool established: return it
                        _logger.debug("Retrieved requestorpool from cache: " + sPoolId);
                        return oRPE._oRequestorPool;
                    }
                }
                // No cached RequestorPool, or RequestorPool is expired
            }

            oRequestorPool = new JDBCRequestorPool(oResultSet, _oDataSource, _sPoolsTable, _sRequestorsTable,
                    _sRequestorPropertiesTable, _sAuthenticationTable, _sPoolPropertiesTable);

            if (_isCacheEnabled) {
                // Add to or update cache
                Date dLastModified = oResultSet.getDate(JDBCRequestorPool.COLUMN_DATE_LAST_MODIFIED);
                RequestorPoolEntry oRPE = new RequestorPoolEntry(dLastModified, oRequestorPool);

                _mRequestorPoolMap.put(oRequestorPool.getID(), oRPE);
            }
        }

        if (oRequestorPool != null)
            _logger.debug("Retrieved requestorpool: " + oRequestorPool);
        else
            _logger.debug("No requestorpool found for requestor: " + sRequestor);
    } catch (SQLException e) {
        _logger.error("Can not read from database", e);
        throw new RequestorException(SystemErrors.ERROR_RESOURCE_RETRIEVE);
    } catch (RequestorException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error during retrieval of requestor: " + sRequestor, e);
        throw new RequestorException(SystemErrors.ERROR_INTERNAL);
    } finally {
        try {
            if (oResultSet != null)
                oResultSet.close();
        } catch (Exception e) {
            _logger.error("Could not close resultset", e);
        }

        try {
            if (oPreparedStatement != null)
                oPreparedStatement.close();
        } catch (Exception e) {
            _logger.error("Could not close statement", e);
        }

        try {
            if (oConnection != null)
                oConnection.close();
        } catch (Exception e) {
            _logger.error("Could not close connection", e);
        }
    }
    return oRequestorPool;
}

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

private int printResultSet(final ResultSet rs) throws Exception {
    int count = 0;
    long empno, empno2;
    String ename, ename2;//  w  w w. j  av  a  2s.  c  o m
    String[] nicknames;
    String[] nicknames2;
    double salary, salary2;
    Date hireDate, hireDate2;

    System.out.println();
    System.out.println("===================================================================");
    System.out.println("   empno        ename      salary       hire_date       nicknames");
    System.out.println("===================================================================");

    while (rs.next()) {
        ++count;

        if (count == 1) {
            assertTrue(rs.isFirst());
        } else {
            assertFalse(rs.isFirst());
        }

        assertEquals(count, rs.getRow());

        empno = rs.getLong(1);
        assertFalse(rs.wasNull());
        empno2 = rs.getLong("empno");
        assertEquals(empno, empno2);
        ename = rs.getString(2);
        ename2 = rs.getString("ename");
        assertEquals(ename, ename2);
        salary = rs.getDouble(3);
        salary2 = rs.getDouble("salary");
        assertEquals(salary, salary2, 0.001);
        hireDate = rs.getDate(4);
        hireDate2 = rs.getDate("hiredate");
        assertEquals(hireDate, hireDate2);
        nicknames = (String[]) rs.getArray(5).getArray();
        nicknames2 = (String[]) rs.getArray("nicknames").getArray();
        assertArrayEquals(nicknames, nicknames2);

        String nodeName = rs.getString(Constants.COLUMN_JCR_NAME);
        assertEquals("testdata-" + count, nodeName);
        assertEquals("/testdatafolder/" + nodeName, rs.getString(Constants.COLUMN_JCR_PATH));
        String nodeId = rs.getString(Constants.COLUMN_JCR_UUID);
        assertTrue(nodeId != null && !nodeId.isEmpty());
        assertTrue(rs.getDouble(Constants.COLUMN_JCR_SCORE) > 0.0);

        assertWrongValueFormatColumn(rs);
        assertNonExistingColumn(rs);

        System.out.println(String.format(REC_OUT_FORMAT, empno, ename, salary,
                new SimpleDateFormat("yyyy-MM-dd").format(hireDate), join(nicknames, ",")));
        System.out.println(String.format(NODE_INFO_OUT_FORMAT, rs.getString("jcr:uuid"),
                rs.getString("jcr:name"), rs.getString("jcr:path"), rs.getDouble("jcr:score")));

        assertEquals(count, empno);
        assertEquals("Name' " + count, ename);
        assertEquals(100000.0 + count, salary, .1);
        assertEquals(getEmpHireDate().getTimeInMillis(), hireDate.getTime());

        assertFalse(rs.rowUpdated());
        assertFalse(rs.rowInserted());
        assertFalse(rs.rowDeleted());
    }

    System.out.println("==================================================");
    System.out.println();

    return count;
}

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

/**
 * Permet de retourner une ArrayList de NodeConceptCandidat par
 * thsaurus//w w w . j  av a2 s .  co m
 * Si le Candidat n'est pas traduit dans la langue en cours, on rcupre
 * l'identifiant pour l'afficher  la place
 *
 * @param ds le pool de connexion
 * @param idConcept
 * @param idThesaurus
 * @param idUser
 * @return Objet Class ArrayList NodeProposition
 */
public NodeProposition getNodePropositionOfUser(HikariDataSource ds, String idConcept, String idThesaurus,
        int idUser) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;

    NodeProposition nodeProposition = null;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT proposition.id_user," + " users.username, proposition.note,"
                        + " proposition.created," + " proposition.modified," + " proposition.concept_parent,"
                        + " proposition.id_group" + " FROM proposition, users WHERE "
                        + " proposition.id_user = users.id_user" + " and proposition.id_concept = '" + idConcept
                        + "'" + " and proposition.id_thesaurus = '" + idThesaurus + "'"
                        + " and proposition.id_user = " + idUser;

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    if (resultSet.next()) {
                        nodeProposition = new NodeProposition();
                        nodeProposition.setId_user(resultSet.getInt("id_user"));
                        nodeProposition.setUser(resultSet.getString("username"));
                        nodeProposition.setNote(resultSet.getString("note"));
                        nodeProposition.setCreated(resultSet.getDate("created"));
                        nodeProposition.setModified(resultSet.getDate("modified"));
                        nodeProposition.setIdConceptParent(resultSet.getString("concept_parent"));
                        nodeProposition.setIdGroup(resultSet.getString("id_group"));
                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List of node Proposition Candidats of Concept Candidat : " + idConcept,
                sqle);
    }
    return nodeProposition;
}

From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java

@Test
public void testDatetime() throws SQLException {
    trace("test DATETIME");
    ResultSet rs;
    Object o;/*w  w w  .ja v a 2s.  c o m*/

    // rs = stat.executeQuery("call date '99999-12-23'");
    // rs.next();
    // assertEquals("99999-12-23", rs.getString(1));
    // rs = stat.executeQuery("call timestamp '99999-12-23 01:02:03.000'");
    // rs.next();
    // assertEquals("99999-12-23 01:02:03.0", rs.getString(1));
    // rs = stat.executeQuery("call date '-99999-12-23'");
    // rs.next();
    // assertEquals("-99999-12-23", rs.getString(1));
    // rs = stat.executeQuery("call timestamp '-99999-12-23 01:02:03.000'");
    // rs.next();
    // assertEquals("-99999-12-23 01:02:03.0", rs.getString(1));

    stat = conn.createStatement();
    // stat.execute("CREATE TABLE test(ID INT PRIMARY KEY,VALUE DATETIME)");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (1,'2011-11-11 0:0:0', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (2,'2002-02-02 02:02:02', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (3,'1800-01-01 0:0:0', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (4,'9999-12-31 23:59:59', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (5,'9999-12-31 23:59:59', 13, 'testDatetime')");
    // stat.execute("INSERT INTO test (column1,column6,column2,column3) VALUES(5,NULL)");
    rs = stat.executeQuery("SELECT column1,column6 FROM test where column3='testDatetime' ORDER BY column1");
    // assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] {
    // Types.INTEGER, Types.TIMESTAMP }, new int[] { 10, 23 }, new int[] { 0,
    // 10 });
    // rs = stat.executeQuery("SELECT * FROM test ORDER BY ID");
    // assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] {
    // Types.INTEGER, Types.TIMESTAMP }, new int[] { 10, 23 }, new int[] { 0,
    // 10 });
    rs.next();
    java.sql.Date date;
    java.sql.Time time;
    Timestamp ts;
    date = rs.getDate(2);
    assertTrue(!rs.wasNull());
    time = rs.getTime(2);
    assertTrue(!rs.wasNull());
    ts = rs.getTimestamp(2);
    assertTrue(!rs.wasNull());
    trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString());
    trace("Date ms: " + date.getTime() + " Time ms:" + time.getTime() + " Timestamp ms:" + ts.getTime());
    trace("1970 ms: " + Timestamp.valueOf("1970-01-01 00:00:00.0").getTime());
    assertEquals(Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), date.getTime());
    assertEquals(Timestamp.valueOf("1970-01-01 00:00:00.0").getTime(), time.getTime());
    assertEquals(Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), ts.getTime());
    assertTrue(date.equals(java.sql.Date.valueOf("2011-11-11")));
    assertTrue(time.equals(java.sql.Time.valueOf("00:00:00")));
    assertTrue(ts.equals(Timestamp.valueOf("2011-11-11 00:00:00.0")));
    assertFalse(rs.wasNull());
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof Timestamp);
    assertTrue(((Timestamp) o).equals(Timestamp.valueOf("2011-11-11 00:00:00")));
    assertFalse(rs.wasNull());
    rs.next();
    date = rs.getDate("COLUMN6");
    assertTrue(!rs.wasNull());
    time = rs.getTime("COLUMN6");
    assertTrue(!rs.wasNull());
    ts = rs.getTimestamp("COLUMN6");
    assertTrue(!rs.wasNull());
    trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString());
    assertEquals("2002-02-02", date.toString());
    assertEquals("02:02:02", time.toString());
    assertEquals("2002-02-02 02:02:02.0", ts.toString());
    rs.next();
    assertEquals("1800-01-01", rs.getDate("column6").toString());
    assertEquals("00:00:00", rs.getTime("column6").toString());
    assertEquals("1800-01-01 00:00:00.0", rs.getTimestamp("column6").toString());
    rs.next();
    assertEquals("9999-12-31", rs.getDate("Column6").toString());
    assertEquals("23:59:59", rs.getTime("Column6").toString());
    assertEquals("9999-12-31 23:59:59.0", rs.getTimestamp("Column6").toString());
    // assertTrue(!rs.next());
}

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

/**
 * Cette fonction permet de rcuprer les termes synonymes suivant un
 * id_term et son thsaurus et sa langue sous forme de classe NodeEM
 *
 * @param ds/*from   w  w w.j a  v  a 2 s .c  o m*/
 * @param idTerm
 * @param idThesaurus
 * @param idLang
 * @return Objet class Concept
 */
public ArrayList<NodeEM> getNonPreferredTerms(HikariDataSource ds, String idTerm, String idThesaurus,
        String idLang) {

    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, created, modified," + " source, status, hiden"
                        + " FROM non_preferred_term" + " WHERE non_preferred_term.id_term = '" + idTerm + "'"
                        + " and non_preferred_term.id_thesaurus = '" + idThesaurus + "'"
                        + " and non_preferred_term.lang ='" + idLang + "'" + " order by lexical_value ASC";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    nodeEMList = new ArrayList<>();
                    while (resultSet.next()) {
                        NodeEM nodeEM = new NodeEM();
                        nodeEM.setLexical_value(resultSet.getString("lexical_value"));
                        nodeEM.setCreated(resultSet.getDate("created"));
                        nodeEM.setModified(resultSet.getDate("modified"));
                        nodeEM.setSource(resultSet.getString("source"));
                        nodeEM.setStatus(resultSet.getString("status"));
                        nodeEM.setHiden(resultSet.getBoolean("hiden"));
                        nodeEMList.add(nodeEM);
                    }
                }

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

    return nodeEMList;
}

From source file:migration.ProjektMigration.java

/**
 * Creates the journalkosten./*from ww  w .  j av  a  2 s. c  o  m*/
 */
public void createJournalkosten() {

    String load_sql;
    Statement load_stmt;
    ResultSet load_rs;

    String store_sql;
    PreparedStatement store_prepstmt;
    final ResultSet store_rs;

    try {

        load_sql = "SELECT IMwStO, IMwStP, IMwStPO, IPreisO, IPreisP, IPreisPO, IWaehrungO, IWaehrungP, IWaehrungPO, OPreisO, OPreisP, OPreisPO, Impact, ImpactDatum, MwStO, MwStP, MwStPO, WaehrungO, WaehrungP, WaehrungPO, Titelnummer FROM ZSTiteltabelle";
        load_stmt = this.leg_con.createStatement();

        store_sql = "INSERT INTO Journalkosten (IMwStO, IMwStP, IMwStPO, IPreisO, IPreisP, IPreisPO, IWaehrungO, IWaehrungP, IWaehrungPO, OPreisO, OPreisP, OPreisPO, impact, impactDatum, mwStO, mwStP, mwStPO, waehrungO, waehrungP, waehrungPO, journal_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        store_prepstmt = this.tgt_con.prepareStatement(store_sql); // evtl.
        // brauchen
        // wir
        // was
        // in
        // Richtung:
        // Statement.RETURN_GENERATED_KEYS

        // logger.info("Lese von ZSTiteltabelle (Journalkosten)");
        load_stmt.execute(load_sql);
        load_rs = load_stmt.getResultSet();

        // logger.info("Schreibe nach Journalkosten");
        while (load_rs.next()) {
            final int titelnummer = load_rs.getInt("Titelnummer");
            final int journalID = this.help.getIdFromIntArray(this.help.getJournals(), titelnummer);
            // ystem.out.println("Titelnummer: " + titelnummer +
            // " JournalID " + journalID);
            if ((titelnummer > 0) && (journalID > 0)) {
                store_prepstmt.setString(1, load_rs.getString("IMwStO"));
                store_prepstmt.setString(2, load_rs.getString("IMwStP"));
                store_prepstmt.setString(3, load_rs.getString("IMwStPO"));
                store_prepstmt.setFloat(4, load_rs.getFloat("IPreisO"));
                store_prepstmt.setFloat(5, load_rs.getFloat("IPreisP"));
                store_prepstmt.setFloat(6, load_rs.getFloat("IPreisPO"));
                store_prepstmt.setString(7, load_rs.getString("IWaehrungO"));
                store_prepstmt.setString(8, load_rs.getString("IWaehrungP"));
                store_prepstmt.setString(9, load_rs.getString("IWaehrungPO"));
                store_prepstmt.setFloat(10, load_rs.getFloat("OPreisO"));
                store_prepstmt.setFloat(11, load_rs.getFloat("OPreisP"));
                store_prepstmt.setFloat(12, load_rs.getFloat("OPreisPO"));
                store_prepstmt.setFloat(13, load_rs.getFloat("Impact"));
                store_prepstmt.setDate(14, load_rs.getDate("ImpactDatum"));
                store_prepstmt.setString(15, load_rs.getString("MwStO"));
                store_prepstmt.setString(16, load_rs.getString("MwStP"));
                store_prepstmt.setString(17, load_rs.getString("MwStPO"));
                store_prepstmt.setString(18, load_rs.getString("WaehrungO"));
                store_prepstmt.setString(19, load_rs.getString("WaehrungP"));
                store_prepstmt.setString(20, load_rs.getString("WaehrungPO"));
                store_prepstmt.setLong(21, journalID);
                store_prepstmt.executeUpdate();
            }
        }

    } catch (final SQLException e) {
        e.printStackTrace(); // To change body of catch statement use File |
                             // Settings | File Templates.
    }

}

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

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*from   w w w.j av a 2  s  . c  om*/
public Document getDocument(final String user, final String password, final String db, final String table,
        final String name, final boolean allowEmpty, final Map<String, String[]> defaultFieldValues)
        throws BackendException {
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try {
        conn = this.connectToDB(user, password, db);
        PostgresDocument doc = this.createEmptyDocument(conn, table, name, db);
        String nameField = this.getNameField(conn, table, db);
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        String queryString = String.format("select * from \"%s\".\"%s\" where \"%s\"='%s'",
                this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name);
        this.logString(queryString, user);
        rs = st.executeQuery(queryString);
        if (this.getNumRows(rs) == 0) {
            if (allowEmpty) {
                if (defaultFieldValues != null) {
                    for (String key : defaultFieldValues.keySet()) {
                        Field field = doc.getAllFields().get(key);
                        if (field != null) {
                            if (field.getType() == FieldType.string || field.getType() == FieldType.text) {
                                field.setValue(defaultFieldValues.get(key)[0]);
                            } else if (field.getType() == FieldType.date) {
                                try {
                                    field.setValue(new SimpleDateFormat("y-M-d")
                                            .parse(defaultFieldValues.get(key)[0]));
                                } catch (ParseException e) {
                                    throw new BackendException(e);
                                }
                            } else if (field.getType() == FieldType.dec) {
                                field.setValue(Integer.valueOf(defaultFieldValues.get(key)[0]));
                            } else if (field.getType() == FieldType.num) {
                                field.setValue(Double.valueOf(defaultFieldValues.get(key)[0]));
                            }
                        }
                    }
                }
                return doc;
            } else {
                throw new DocumentNotFoundException(String.format("Document '%s' not found in table '%s.%s'.",
                        name, this.getSchemaName(table, db), this.getPlainTableName(table)));
            }
        }
        rs.next();
        ResultSetMetaData md = rs.getMetaData();
        for (int i = 1; i <= md.getColumnCount(); i++) {
            Field field = doc.getAllFields().get(md.getColumnName(i));
            if (field.getType() == FieldType.string || field.getType() == FieldType.text) {
                field.setValue(rs.getString(i));
            } else if (field.getType() == FieldType.date) {
                field.setValue(rs.getDate(i));
            } else if (field.getType() == FieldType.dec) {
                field.setValue(rs.getInt(i));
            } else if (field.getType() == FieldType.num) {
                field.setValue(rs.getDouble(i));
            }
        }
        return doc;
    } catch (SQLException e) {
        throw new BackendException(e);
    } catch (ClassNotFoundException e) {
        throw new BackendException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(st);
        DbUtils.closeQuietly(conn);
    }
}

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

/**
 * Cette fonction permet de rcuprer l'historique des termes synonymes d'un terme
 *
 * @param ds/*from   ww w .j  av a 2s  .c o  m*/
 * @param idTerm
 * @param idThesaurus
 * @param idLang
 * @return Objet class Concept
 */
public ArrayList<NodeEM> getNonPreferredTermsHistoriqueAll(HikariDataSource ds, String idTerm,
        String idThesaurus, String idLang) {

    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"
                        + " order by modified DESC, lexical_value ASC";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    nodeEMList = new ArrayList<>();
                    while (resultSet.next()) {
                        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 all historique of Term : " + idTerm, sqle);
    }

    return nodeEMList;
}

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

/**
 * Cette fonction permet de rcuprer l'historique d'un terme
 *
 * @param ds/*from  w  ww.  j  a  v  a  2s.  c  o m*/
 * @param idTerm
 * @param idThesaurus
 * @param idLang
 * @return Objet class Concept
 */
public ArrayList<Term> getTermsHistoriqueAll(HikariDataSource ds, String idTerm, String idThesaurus,
        String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<Term> nodeTermList = null;

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

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    nodeTermList = new ArrayList<>();
                    while (resultSet.next()) {
                        Term t = new Term();
                        t.setId_term(idTerm);
                        t.setId_thesaurus(idThesaurus);
                        t.setLexical_value(resultSet.getString("lexical_value"));
                        t.setModified(resultSet.getDate("modified"));
                        t.setSource(resultSet.getString("source"));
                        t.setStatus(resultSet.getString("status"));
                        t.setIdUser(resultSet.getString("username"));
                        t.setLang(idLang);
                        nodeTermList.add(t);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting all historique of Term : " + idTerm, sqle);
    }

    return nodeTermList;
}

From source file:com.erbjuder.logger.server.rest.util.ResultSetConverter.java

public List<String> toStringList(ResultSet rs) throws Exception {

    List<String> list = new ArrayList<String>();
    try {/*from   w  ww  .  j  a v a 2  s.  c  om*/

        // we will need the column names, this will save the table meta-data like column nmae.
        java.sql.ResultSetMetaData rsmd = rs.getMetaData();
        //loop through the ResultSet
        while (rs.next()) {

            //figure out how many columns there are
            int numColumns = rsmd.getColumnCount();

            //each row in the ResultSet will be converted to a JSON Object
            StringBuilder builder = new StringBuilder();
            // loop through all the columns and place them into the JSON Object
            for (int i = 1; i < numColumns + 1; i++) {
                String column_name = rsmd.getColumnName(i);

                if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
                    builder.append(rs.getArray(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
                    builder.append(rs.getInt(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
                    builder.append(rs.getBoolean(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
                    builder.append(rs.getBlob(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
                    builder.append(rs.getDouble(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
                    builder.append(rs.getFloat(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
                    builder.append(rs.getInt(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
                    builder.append(rs.getNString(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
                    //                        temp = rs.getString(column_name); //saving column data to temp variable
                    //                        temp = ESAPI.encoder().canonicalize(temp); //decoding data to base state
                    //                        temp = ESAPI.encoder().encodeForHTML(temp); //encoding to be browser safe
                    //                        obj.put(column_name, temp); //putting data into JSON object
                    //                    
                    builder.append(rs.getNString(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
                    builder.append(rs.getInt(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
                    builder.append(rs.getInt(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
                    builder.append(rs.getDate(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.TIME) {
                    builder.append(rs.getTime(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                    builder.append(rs.getTimestamp(column_name));

                } else if (rsmd.getColumnType(i) == java.sql.Types.NUMERIC) {
                    builder.append(rs.getBigDecimal(column_name));

                } else {
                    builder.append(rs.getObject(column_name));

                }
            } //end foreach
            list.add(builder.toString());
        } //end while
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list; //return String list

}