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:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testUnsignedTimeDateWithLiteral() throws Exception {
    String tableName = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + "  (k1 INTEGER NOT NULL,"
            + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))";
    conn.createStatement().execute(ddl);
    String dml = "UPSERT INTO " + tableName + " VALUES (1, "
            + "'2010-06-20 12:00:00', '2012-07-28 12:00:00', '2015-12-25 12:00:00')";
    conn.createStatement().execute(dml);
    conn.commit();/*from  w  ww .  j av a2s . c  om*/

    ResultSet rs = conn.createStatement().executeQuery("SELECT k1, unsignedDates, "
            + "unsignedTimestamps, unsignedTimes FROM " + tableName + " where k1 = 1");
    assertTrue(rs.next());
    assertEquals(DateUtil.parseDate("2010-06-20 12:00:00"), rs.getDate(2));
    assertEquals(DateUtil.parseTimestamp("2012-07-28 12:00:00"), rs.getTimestamp(3));
    assertEquals(DateUtil.parseTime("2015-12-25 12:00:00"), rs.getTime(4));
    assertFalse(rs.next());
}

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

/**
 * pour pouvoir obtener une list des Notes a partir du idTerm
 * sans conter avec le language/* ww w .  java 2  s  .  c  o  m*/
 * @param ds
 * @param idTerm
 * @param idThesaurus
 * @return 
 */
public ArrayList<NodeNote> getListNotesTerm2(HikariDataSource ds, String idTerm, String idThesaurus) {

    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT note.id, note.lang, note.notetypecode,"
                        + " note.lexicalvalue, note.created," + " note.modified FROM note, note_type"
                        + " WHERE note.notetypecode = note_type.code" + " and note_type.isterm = true"
                        + " and note.id_term = '" + idTerm + "'" + " and note.id_thesaurus = '" + idThesaurus
                        + "'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeNote nodeNote = new NodeNote();
                    nodeNote.setId_term(idTerm);
                    nodeNote.setId_note(resultSet.getInt("id"));
                    nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                    nodeNote.setModified(resultSet.getDate("modified"));
                    nodeNote.setCreated(resultSet.getDate("created"));
                    nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                    nodeNote.setLang(resultSet.getString("lang"));
                    nodeNotes.add(nodeNote);
                }

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

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testNullDate() throws Exception {

    ResultSet rs = conn.createStatement().executeQuery(
            "SELECT a_date, entity_id from " + this.tableName + " WHERE entity_id = '" + ROW10 + "'");
    assertNotNull(rs);/*w ww  .  j  a v a2  s .  c  o m*/
    assertTrue(rs.next());
    assertEquals(ROW10, rs.getString(2));
    assertNull(rs.getDate(1));
    assertNull(rs.getDate(1, GregorianCalendar.getInstance()));
    assertFalse(rs.next());
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testFunctionOnNullDate() throws Exception {
    ResultSet rs = conn.createStatement().executeQuery(
            "SELECT \"YEAR\"(a_date), entity_id from " + this.tableName + " WHERE entity_id = '" + ROW10 + "'");
    assertNotNull(rs);//  w  w  w . j  a  v  a  2  s . co  m
    assertTrue(rs.next());
    assertEquals(ROW10, rs.getString(2));
    assertNull(rs.getDate(1));
    assertNull(rs.getDate(1, GregorianCalendar.getInstance()));
    assertFalse(rs.next());
}

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

/**
* pour pouvoir obtener une list des Notes a partir du idConcept
* sans conter avec le language/*w w  w.  j a  va2 s .  c o m*/
* @param ds
* @param idConcept
* @param idThesaurus
* @return 
*/
public ArrayList<NodeNote> getListNotesConcept2(HikariDataSource ds, String idConcept, String idThesaurus) {

    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT note.id, note.lang, note.notetypecode,"
                        + " note.lexicalvalue, note.created," + " note.modified FROM note, note_type"
                        + " WHERE note.notetypecode = note_type.code" + " and note_type.isconcept = true"
                        + " and note.id_concept = '" + idConcept + "'" + " and note.id_thesaurus = '"
                        + idThesaurus + "'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeNote nodeNote = new NodeNote();
                    nodeNote.setId_concept(idConcept);
                    nodeNote.setId_note(resultSet.getInt("id"));
                    nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                    nodeNote.setModified(resultSet.getDate("modified"));
                    nodeNote.setCreated(resultSet.getDate("created"));
                    nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                    nodeNote.setLang(resultSet.getString("lang"));
                    nodeNotes.add(nodeNote);
                }

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

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

/**
 * Cette focntion permet de retourner la liste de l'historique des notes
 * pour un concept (type CustomNote, ScopeNote, HistoryNote)  une date
 * prcise// w  ww . j  a v a2  s  .c o  m
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @param idTerm
 * @param idLang
 * @param date
 * @return ArrayList des notes sous forme de Class NodeNote
 */
public ArrayList<NodeNote> getNoteHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus,
        String idTerm, String idLang, Date date) {

    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT id, notetypecode, lexicalvalue, modified, username FROM note_historique, users"
                        + " WHERE id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'"
                        + " and (id_concept = '" + idConcept + "' OR id_term = '" + idTerm + "' )"
                        + " and note_historique.id_user=users.id_user" + " and modified <= '" + date.toString()
                        + "' order by modified DESC";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    boolean exist = false;
                    for (NodeNote nn : nodeNotes) {
                        if (nn.getNotetypecode().equals(resultSet.getString("notetypecode"))) {
                            if (nn.getModified().before(resultSet.getDate("modified"))) {
                                NodeNote nodeNote = new NodeNote();
                                nodeNote.setId_concept(idConcept);
                                nodeNote.setId_term(idTerm);
                                nodeNote.setId_note(resultSet.getInt("id"));
                                nodeNote.setLang(idLang);
                                nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                                nodeNote.setModified(resultSet.getDate("modified"));
                                nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                                nodeNote.setIdUser(resultSet.getString("username"));
                                nodeNotes.add(nodeNote);
                            }
                            exist = true;
                        }
                    }
                    if (!exist) {
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setId_concept(idConcept);
                        nodeNote.setId_term(idTerm);
                        nodeNote.setId_note(resultSet.getInt("id"));
                        nodeNote.setLang(idLang);
                        nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                        nodeNote.setModified(resultSet.getDate("modified"));
                        nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                        nodeNote.setIdUser(resultSet.getString("username"));
                        nodeNotes.add(nodeNote);
                    }

                }

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

From source file:org.apache.openaz.xacml.std.pip.engines.jdbc.ConfigurableJDBCResolver.java

/**
 * Creates an {@link org.apache.openaz.xacml.api.Attribute} from the value associated with the field with
 * the given <code>fieldName</code>.
 *
 * @param resultSet the {@link java.sql.ResultSet} containing the current row from the database
 * @param fieldName the <code>String</code> name of the field containing the attribute value
 * @param pipRequestAttribute the {@link org.apache.openaz.xacml.api.pip.PIPRequest} for the
 *            <code>Attribute</code> to create
 * @return a new <code>Attribute</code> with the value of the given <code>fieldName</code>.
 *//*from w  ww . j  a va 2  s  . c  o  m*/
protected Attribute getAttributeFromResultSet(ResultSet resultSet, String fieldName,
        PIPRequest pipRequestAttribute) {
    AttributeValue<?> attributeValue = null;
    Identifier identifierDataType = pipRequestAttribute.getDataTypeId();
    try {
        DataType<?> dataType = dataTypeFactory.getDataType(identifierDataType);
        if (dataType == null) {
            this.logger.warn("Unknown data type " + pipRequestAttribute.getDataTypeId().stringValue());
            return null;
        }
        /*
         * Try to find the column index
         */

        int columnIndex = -1;

        try {
            columnIndex = resultSet.findColumn(fieldName);
        } catch (Exception e) {
            /*
             * The field name could be an integer, let's try that
             */
            try {
                columnIndex = Integer.parseInt(fieldName);
            } catch (Exception e1) {
                logger.error("Failed to find column with label " + fieldName);
            }
        }
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Column " + fieldName + " maps to column index " + columnIndex);
        }

        /*
         * Catch special cases for database types
         */
        if (identifierDataType.equals(XACML3.ID_DATATYPE_BOOLEAN)) {
            attributeValue = dataType.createAttributeValue(resultSet.getBoolean(columnIndex));
        } else if (identifierDataType.equals(XACML3.ID_DATATYPE_DATE)
                || identifierDataType.equals(XACML3.ID_DATATYPE_DATETIME)) {
            attributeValue = dataType.createAttributeValue(resultSet.getDate(columnIndex));
        } else if (identifierDataType.equals(XACML3.ID_DATATYPE_DOUBLE)) {
            attributeValue = dataType.createAttributeValue(resultSet.getDouble(columnIndex));
        } else if (identifierDataType.equals(XACML3.ID_DATATYPE_INTEGER)) {
            attributeValue = dataType.createAttributeValue(resultSet.getInt(columnIndex));
        } else {
            /*
             * Default to convert the string value from the database to the requested data type
             */
            String stringValue = resultSet.getString(columnIndex);
            if (stringValue != null) {
                attributeValue = dataType.createAttributeValue(stringValue);
            }
        }
    } catch (Exception ex) {
        this.logger.error("Exception getting value for fieldName '" + fieldName + "' as a "
                + identifierDataType.stringValue() + ": " + ex.toString(), ex);
        return null;
    }
    String issuer = this.defaultIssuer;
    if (pipRequestAttribute.getIssuer() != null) {
        issuer = pipRequestAttribute.getIssuer();
    }
    return new StdAttribute(pipRequestAttribute.getCategory(), pipRequestAttribute.getAttributeId(),
            attributeValue, issuer, false);
}

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

/**
 * Permet de retourner un thsaurus par identifiant et par langue / ou null
 * si rien cette fonction ne retourne pas les dtails et les traductions
 *
 * @param ds le pool de connexion/*from w  ww  . ja  va  2s  .c o m*/
 * @param idThesaurus
 * @param idLang
 * @return Objet Class Thesaurus
 */
public Thesaurus getThisThesaurus(HikariDataSource ds, String idThesaurus, String idLang) {
    idLang = idLang.trim();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    Thesaurus thesaurus = null;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select * from thesaurus_label where id_thesaurus = '" + idThesaurus
                        + "' and lang = '" + idLang + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    if (resultSet.getString("lang") == null) {
                        return null;
                    } else {
                        thesaurus = new Thesaurus();
                        thesaurus.setId_thesaurus(idThesaurus);
                        thesaurus.setContributor(resultSet.getString("contributor"));
                        thesaurus.setCoverage(resultSet.getString("coverage"));
                        thesaurus.setCreator(resultSet.getString("creator"));
                        thesaurus.setCreated(resultSet.getDate("created"));
                        thesaurus.setModified(resultSet.getDate("modified"));
                        thesaurus.setDescription(resultSet.getString("description"));
                        thesaurus.setFormat(resultSet.getString("format"));
                        thesaurus.setLanguage(resultSet.getString("lang"));
                        thesaurus.setPublisher(resultSet.getString("publisher"));
                        thesaurus.setRelation(resultSet.getString("relation"));
                        thesaurus.setRights(resultSet.getString("rights"));
                        thesaurus.setSource(resultSet.getString("source"));
                        thesaurus.setSubject(resultSet.getString("subject"));
                        thesaurus.setTitle(resultSet.getString("title"));
                        thesaurus.setType(resultSet.getString("type"));
                    }
                }
                resultSet.close();

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting This Thesaurus : " + idThesaurus, sqle);
    }
    return thesaurus;
}

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

/**
 * Cette focntion permet de retourner la liste des notes pour un Term(type
 * HistoryNote, Definition, EditotrialNote)
 *
 * @param ds/*from w  w  w.j a  v a2s  .  co  m*/
 * @param idThesaurus
 * @param idTerm
 * @param idLang
 * @return ArrayList des notes sous forme de Class NodeNote
 */
public ArrayList<NodeNote> getListNotesTerm(HikariDataSource ds, String idTerm, String idThesaurus,
        String idLang) {

    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created,"
                        + " note.modified FROM note, note_type" + " WHERE note.notetypecode = note_type.code"
                        + " and note_type.isterm = true" + " and note.id_term = '" + idTerm + "'"
                        + " and note.lang ='" + idLang + "'" + " and note.id_thesaurus = '" + idThesaurus + "'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeNote nodeNote = new NodeNote();
                    nodeNote.setId_term(idTerm);
                    nodeNote.setId_note(resultSet.getInt("id"));
                    nodeNote.setLang(idLang);
                    nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                    nodeNote.setModified(resultSet.getDate("modified"));
                    nodeNote.setCreated(resultSet.getDate("created"));
                    nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                    nodeNotes.add(nodeNote);
                }

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

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

/**
 * Cette focntion permet de retourner la liste des notes pour un concept
 * (type CustomNote, ScopeNote, HistoryNote)
 *
 * @param ds//w  w  w  . j  a v a 2s .  c  o  m
 * @param idConcept
 * @param idThesaurus
 * @param idLang
 * @return ArrayList des notes sous forme de Class NodeNote
 */
public ArrayList<NodeNote> getListNotesConcept(HikariDataSource ds, String idConcept, String idThesaurus,
        String idLang) {

    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created,"
                        + " note.modified FROM note, note_type" + " WHERE note.notetypecode = note_type.code"
                        + " and note_type.isconcept = true" + " and note.id_concept = '" + idConcept + "'"
                        + " and note.lang ='" + idLang + "'" + " and note.id_thesaurus = '" + idThesaurus + "'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeNote nodeNote = new NodeNote();
                    nodeNote.setId_concept(idConcept);
                    nodeNote.setId_note(resultSet.getInt("id"));
                    nodeNote.setLang(idLang);
                    nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                    nodeNote.setModified(resultSet.getDate("modified"));
                    nodeNote.setCreated(resultSet.getDate("created"));
                    nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                    nodeNotes.add(nodeNote);
                }

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