Example usage for java.sql Types TIMESTAMP

List of usage examples for java.sql Types TIMESTAMP

Introduction

In this page you can find the example usage for java.sql Types TIMESTAMP.

Prototype

int TIMESTAMP

To view the source code for java.sql Types TIMESTAMP.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP.

Usage

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void delete(final Ligplaats ligplaats) {
    try {//from ww  w.j  ava 2s  .com
        deleteNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats);
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_ligplaats"
                        + " where bag_ligplaats_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, ligplaats.getIdentificatie());
                ps.setLong(2, ligplaats.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(ligplaats.getBegindatumTijdvakGeldigheid().getTime()));
                if (ligplaats.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(ligplaats.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void delete(final Standplaats standplaats) {
    try {/*from ww  w.  ja v  a2 s .c o  m*/
        deleteNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaats);
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_standplaats"
                        + " where bag_standplaats_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, standplaats.getIdentificatie());
                ps.setLong(2, standplaats.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(standplaats.getBegindatumTijdvakGeldigheid().getTime()));
                if (standplaats.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(standplaats.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:com.mirth.connect.donkey.server.data.jdbc.JdbcDao.java

private static String sqlTypeToString(int sqlType) {
    switch (sqlType) {
    case Types.ARRAY:
        return "ARRAY";
    case Types.BIGINT:
        return "BIGINT";
    case Types.BINARY:
        return "BINARY";
    case Types.BIT:
        return "BIT";
    case Types.BLOB:
        return "BLOB";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.CHAR:
        return "CHAR";
    case Types.CLOB:
        return "CLOB";
    case Types.DATALINK:
        return "DATALINK";
    case Types.DATE:
        return "DATE";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.FLOAT:
        return "FLOAT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.NULL:
        return "NULL";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.OTHER:
        return "OTHER";
    case Types.REAL:
        return "REAL";
    case Types.REF:
        return "REF";
    case Types.ROWID:
        return "ROWID";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.SQLXML:
        return "SQLXML";
    case Types.STRUCT:
        return "STRUCT";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.TINYINT:
        return "TINYINT";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.VARCHAR:
        return "VARCHAR";
    default:/*  w ww . j a  v  a  2s .  co m*/
        return "UNKNOWN";
    }
}

From source file:ProcessRequest.java

public JSONArray parseQueryResults(ResultSet rs, String table) throws SQLException, JSONException {
    JSONArray resultJSONArray = new JSONArray();
    ResultSetMetaData rsmd = rs.getMetaData();
    int columns = rsmd.getColumnCount();
    while (rs.next()) {
        JSONObject result = new JSONObject();
        JSONObject resultMeta = new JSONObject();
        resultMeta.put("table", table);
        result.put("metadata", resultMeta);
        for (int i = 1; i <= columns; i++) {
            //out.println("<td>"+rs.getString(i)+"</td>");
            int type = rsmd.getColumnType(i);
            //result.put(rsmd.getColumnName(i), rs.get)
            switch (type) {
            case Types.BIT:
                result.put(rsmd.getColumnName(i), rs.getBoolean(i));
                break;
            case Types.TINYINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.SMALLINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.INTEGER:
                //System.out.println(rsmd.getColumnName(i) + "  type: "+type);
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.BIGINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.FLOAT:
                result.put(rsmd.getColumnName(i), rs.getFloat(i));
                break;
            case Types.REAL:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.DOUBLE:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.NUMERIC:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.DECIMAL:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.CHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.VARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.LONGVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.DATE: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }//w  w  w. j ava 2s . com
            case Types.TIME: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.TIMESTAMP: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.BINARY:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.VARBINARY:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.LONGVARBINARY:
                result.put(rsmd.getColumnName(i), rs.getLong(i));
                break;
            case Types.NULL:
                result.put(rsmd.getColumnName(i), "");
                break;
            case Types.BOOLEAN:
                result.put(rsmd.getColumnName(i), rs.getBoolean(i));
                break;
            case Types.ROWID:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.NCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.NVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.LONGNVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.SQLXML:
            case Types.NCLOB:
            case Types.DATALINK:
            case Types.REF:
            case Types.OTHER:
            case Types.JAVA_OBJECT:
            case Types.DISTINCT:
            case Types.STRUCT:
            case Types.ARRAY:
            case Types.BLOB:
            case Types.CLOB:
            default:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            }
        }
        //if(table.equals("Ticket"))
        //System.out.println(result.toString(5));
        resultJSONArray.put(result);
    }
    return resultJSONArray;
}

From source file:ProcessRequest.java

public void parseQueryResults(ResultSet rs, String table, OutputStream os, boolean append)
        throws SQLException, JSONException, IOException {
    //JSONArray resultJSONArray = new JSONArray();
    ResultSetMetaData rsmd = rs.getMetaData();
    int columns = rsmd.getColumnCount();
    rs.last();//from   w w  w.  j av  a  2s . co  m
    int rows = rs.getRow();
    os.write(new String("total rows: " + rows).getBytes());
    rs.first();
    int rowCount = 0;
    while (rs.next()) {
        if (!rs.isFirst() || append) {
            os.write(new String(",\n").getBytes());
            os.write(new String("" + rowCount).getBytes());
        }
        if (rowCount >= 69)
            System.out.println("break point");
        rowCount++;
        JSONObject result = new JSONObject();
        JSONObject resultMeta = new JSONObject();
        resultMeta.put("table", table);
        result.put("metadata", resultMeta);
        for (int i = 1; i <= columns; i++) {
            //out.println("<td>"+rs.getString(i)+"</td>");
            int type = rsmd.getColumnType(i);
            //result.put(rsmd.getColumnName(i), rs.get)
            switch (type) {
            case Types.BIT:
                result.put(rsmd.getColumnName(i), rs.getBoolean(i));
                break;
            case Types.TINYINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.SMALLINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.INTEGER:
                //System.out.println(rsmd.getColumnName(i) + "  type: "+type);
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.BIGINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.FLOAT:
                result.put(rsmd.getColumnName(i), rs.getFloat(i));
                break;
            case Types.REAL:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.DOUBLE:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.NUMERIC:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.DECIMAL:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.CHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.VARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.LONGVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.DATE: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.TIME: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.TIMESTAMP: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.BINARY:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.VARBINARY:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.LONGVARBINARY:
                result.put(rsmd.getColumnName(i), rs.getLong(i));
                break;
            case Types.NULL:
                result.put(rsmd.getColumnName(i), "");
                break;
            case Types.BOOLEAN:
                result.put(rsmd.getColumnName(i), rs.getBoolean(i));
                break;
            case Types.ROWID:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.NCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.NVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.LONGNVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.SQLXML:
            case Types.NCLOB:
            case Types.DATALINK:
            case Types.REF:
            case Types.OTHER:
            case Types.JAVA_OBJECT:
            case Types.DISTINCT:
            case Types.STRUCT:
            case Types.ARRAY:
            case Types.BLOB:
            case Types.CLOB:
            default:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            }
        }
        //if(table.equals("Ticket"))
        //System.out.println(result.toString(5));
        //if(result.getInt("TicketNumber")==126868)
        //   System.out.println("break point");
        //resultJSONArray.put(result);
        os.write(result.toString(5).getBytes());
    }
    //return resultJSONArray;
}

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Indicates whether the given SQL data type is a temporal type.
 * This method is called internally by the conversion methods
 * <code>convertNumeric</code> and <code>convertTemporal</code>.
 *
 * @param type one of the constants from <code>java.sql.Types</code>
 * @return <code>true</code> if the given type is <code>DATE</code>,
 *         <code>TIME</code>, or <code>TIMESTAMP</code>;
 *         <code>false</code> otherwise
 *//*from w  w  w.j a  va2s  . co  m*/
private boolean isTemporal(int type) {
    switch (type) {
    case java.sql.Types.DATE:
    case java.sql.Types.TIME:
    case java.sql.Types.TIMESTAMP:
        return true;
    default:
        return false;
    }
}

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Converts the given <code>Object</code> in the Java programming language
 * to the standard object mapping for the specified SQL target data type.
 * The conversion must be to a string or temporal type, and there are also
 * restrictions on the type to be converted.
 * <P>/*from   w  w  w.j  a  va  2  s.  com*/
 * <TABLE ALIGN="CENTER" BORDER CELLPADDING=10 BORDERCOLOR="#0000FF"
 * <CAPTION ALIGN="CENTER"><B>Parameters and Return Values</B></CAPTION>
 * <TR>
 *   <TD><B>Source SQL Type</B>
 *   <TD><B>Target SQL Type</B>
 *   <TD><B>Object Returned</B>
 * </TR>
 * <TR>
 *   <TD><code>TIMESTAMP</code>
 *   <TD><code>DATE</code>
 *   <TD><code>java.sql.Date</code>
 * </TR>
 * <TR>
 *   <TD><code>TIMESTAMP</code>
 *   <TD><code>TIME</code>
 *   <TD><code>java.sql.Time</code>
 * </TR>
 * <TR>
 *   <TD><code>TIME</code>
 *   <TD><code>TIMESTAMP</code>
 *   <TD><code>java.sql.Timestamp</code>
 * </TR>
 * <TR>
 *   <TD><code>DATE</code>, <code>TIME</code>, or <code>TIMESTAMP</code>
 *   <TD><code>CHAR</code>, <code>VARCHAR</code>, or <code>LONGVARCHAR</code>
 *   <TD><code>java.lang.String</code>
 * </TR>
 * </TABLE>
 * <P>
 * If the source type and target type are the same,
 * the given object is simply returned.
 *
 * @param srcObj the <code>Object</code> in the Java programming language
 *               that is to be converted to the target type
 * @param srcType the data type that is the standard mapping in SQL of the
 *                object to be converted; must be one of the constants in
 *                <code>java.sql.Types</code>
 * @param trgType the SQL data type to which to convert the given object;
 *                must be one of the following constants in
 *                <code>java.sql.Types</code>: <code>DATE</code>,
 *         <code>TIME</code>, <code>TIMESTAMP</code>, <code>CHAR</code>,
 *         <code>VARCHAR</code>, or <code>LONGVARCHAR</code>
 * @return an <code>Object</code> value.that is
 *         the standard object mapping for the target SQL type
 * @throws SQLException if the given target type is not one of the string or
 *         temporal types in <code>java.sql.Types</code>
 */
private Object convertTemporal(Object srcObj, int srcType, int trgType) throws SQLException {

    if (srcType == trgType) {
        return srcObj;
    }

    if (isNumeric(trgType) == true || (isString(trgType) == false && isTemporal(trgType) == false)) {
        throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
    }

    try {
        switch (trgType) {
        case java.sql.Types.DATE:
            if (srcType == java.sql.Types.TIMESTAMP) {
                return new java.sql.Date(((java.sql.Timestamp) srcObj).getTime());
            } else {
                throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
            }
        case java.sql.Types.TIMESTAMP:
            if (srcType == java.sql.Types.TIME) {
                return new Timestamp(((java.sql.Time) srcObj).getTime());
            } else {
                return new Timestamp(((java.sql.Date) srcObj).getTime());
            }
        case java.sql.Types.TIME:
            if (srcType == java.sql.Types.TIMESTAMP) {
                return new Time(((java.sql.Timestamp) srcObj).getTime());
            } else {
                throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
            }
        case java.sql.Types.CHAR:
        case java.sql.Types.VARCHAR:
        case java.sql.Types.LONGVARCHAR:
            return new String(srcObj.toString());
        default:
            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
        }
    } catch (NumberFormatException ex) {
        throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
    }

}

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Sets the designated column in either the current row or the insert
 * row of this <code>CachedRowSetImpl</code> object with the given
 * <code>Timestamp</code> object.
 *
 * This method updates a column value in either the current row or
 * the insert row of this rowset, but it does not update the
 * database.  If the cursor is on a row in the rowset, the
 * method {@link #updateRow} must be called to update the database.
 * If the cursor is on the insert row, the method {@link #insertRow}
 * must be called, which will insert the new row into both this rowset
 * and the database. Both of these methods must be called before the
 * cursor moves to another row./*from  w w w .j av a 2 s  . c o  m*/
 *
 * @param columnIndex the first column is <code>1</code>, the second
 *        is <code>2</code>, and so on; must be <code>1</code> or larger
 *        and equal to or less than the number of columns in this rowset
 * @param x the new column value
 * @throws SQLException if (1) the given column index is out of bounds,
 *            (2) the cursor is not on one of this rowset's rows or its
 *            insert row, (3) the type of the designated column is not
 *            an SQL <code>DATE</code>, <code>TIME</code>, or
 *            <code>TIMESTAMP</code>, or (4) this rowset is
 *            <code>ResultSet.CONCUR_READ_ONLY</code>
 */
public void updateTimestamp(int columnIndex, java.sql.Timestamp x) throws SQLException {
    // sanity check.
    checkIndex(columnIndex);
    // make sure the cursor is on a valid row
    checkCursor();

    Object obj = convertTemporal(x, java.sql.Types.TIMESTAMP, RowSetMD.getColumnType(columnIndex));

    getCurrentRow().setColumnObject(columnIndex, obj);
}

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Retrieves the value of the designated column in the current row
 * of this <code>CachedRowSetImpl</code> object as a <code>java.sql.Timestamp</code>
 * object, using the given <code>Calendar</code> object to construct an
 * appropriate millisecond value for the date.
 *
 * @param columnIndex the first column is <code>1</code>, the second
 *        is <code>2</code>, and so on; must be <code>1</code> or larger
 *        and equal to or less than the number of columns in the rowset
 * @param cal the <code>java.util.Calendar</code> object to use in
 *            constructing the date//from   w  w  w  . j a  va 2 s  . c om
 * @return the column value; if the value is SQL <code>NULL</code>,
 *         the result is <code>null</code>
 * @throws SQLException if (1) the given column name is not the name of
 *            a column in this rowset, (2) the cursor is not on one of
 *            this rowset's rows or its insert row, or (3) the designated
 *            column does not store an SQL <code>TIME</code> or
 *            <code>TIMESTAMP</code> value
 */
public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
    Object value;

    // sanity check.
    checkIndex(columnIndex);
    // make sure the cursor is on a valid row
    checkCursor();

    setLastValueNull(false);
    value = getCurrentRow().getColumnObject(columnIndex);

    // check for SQL NULL
    if (value == null) {
        setLastValueNull(true);
        return null;
    }

    value = convertTemporal(value, RowSetMD.getColumnType(columnIndex), java.sql.Types.TIMESTAMP);

    // create a default calendar
    Calendar defaultCal = Calendar.getInstance();
    // set the time in the default calendar
    defaultCal.setTime((java.util.Date) value);

    /*
     * Now we can pull the pieces of the date out
     * of the default calendar and put them into
     * the user provided calendar
     */
    cal.set(Calendar.YEAR, defaultCal.get(Calendar.YEAR));
    cal.set(Calendar.MONTH, defaultCal.get(Calendar.MONTH));
    cal.set(Calendar.DAY_OF_MONTH, defaultCal.get(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, defaultCal.get(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, defaultCal.get(Calendar.MINUTE));
    cal.set(Calendar.SECOND, defaultCal.get(Calendar.SECOND));

    return new java.sql.Timestamp(cal.getTime().getTime());
}