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:org.easyrec.mahout.store.impl.MahoutDataModelMappingDAOMysqlImpl.java

@ShortCacheable
@Override/*from   ww  w. jav a  2 s . c o  m*/
public LongPrimitiveIterator getItemIDs(int tenantId, Date cutoffDate, int actionTypeId) {
    Object[] args = new Object[] { tenantId, cutoffDate, actionTypeId };
    int[] argTypes = new int[] { Types.INTEGER, Types.TIMESTAMP, Types.INTEGER };

    return new LongResultSetIteratorMysql(getDataSource(), getItemIDsQuery, args, argTypes);
}

From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java

@Override
public void updateStepExecution(StepExecution stepExecution) {

    validateStepExecution(stepExecution);
    Assert.notNull(stepExecution.getId(),
            "StepExecution Id cannot be null. StepExecution must saved" + " before it can be updated.");

    // Do not check for existence of step execution considering
    // it is saved at every commit point.

    String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription());

    // Attempt to prevent concurrent modification errors by blocking here if
    // someone is already trying to do it.
    synchronized (stepExecution) {

        Integer version = stepExecution.getVersion() + 1;
        Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(),
                stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
                stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
                stepExecution.getExitStatus().getExitCode(), exitDescription, version,
                stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(),
                stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(),
                stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() };
        int count = getJdbcTemplate().update(getQuery(UPDATE_STEP_EXECUTION), parameters,
                new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP,
                        Types.BIGINT, Types.INTEGER });

        // Avoid concurrent modifications...
        if (count == 0) {
            int curentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION),
                    new Object[] { stepExecution.getId() }, Integer.class);
            throw new OptimisticLockingFailureException(
                    "Attempt to update step execution id=" + stepExecution.getId() + " with wrong version ("
                            + stepExecution.getVersion() + "), where current version is " + curentVersion);
        }//from  w ww .  j av  a 2s .c  o  m

        stepExecution.incrementVersion();

    }
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectSQLServer.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        return getFromResultSetString(rs, index, column);
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.TINYINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        return getFromResultSetTimestamp(rs, index, column);
    }/*ww w  .j  ava 2s. c o  m*/
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

From source file:oscar.util.SqlUtils.java

private static Object getNewType(ResultSet rs, int colNum) {
    int type = 0;
    try {/*from w w w. j  av  a  2  s .  c  om*/
        type = rs.getMetaData().getColumnType(colNum);
        switch (type) {
        case Types.LONGVARCHAR:
        case Types.CHAR:
        case Types.VARCHAR:
            return oscar.Misc.getString(rs, colNum);
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return new Integer(rs.getInt(colNum));
        case Types.BIGINT:
            return new Long(rs.getLong(colNum));
        case Types.FLOAT:
        case Types.DECIMAL:
        case Types.REAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
            return new Double(rs.getDouble(colNum));
        // case Types.B
        case Types.BIT:
            return new Boolean(rs.getBoolean(colNum));
        case Types.TIMESTAMP:
        case Types.DATE:
        case Types.TIME:
            return rs.getDate(colNum);
        default:
            return rs.getObject(colNum);
        }
    } catch (Exception e) {
        MiscUtils.getLogger().error("Error", e);
    }
    return null;
}

From source file:com.squid.core.domain.operators.ExtendedType.java

private String getTypeName(int SQLType) {
    switch (SQLType) {
    case Types.ARRAY:
        return "ARRAY";
    case Types.BIGINT:
        return "INTEGER";
    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.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.NCHAR:
        return "NCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.NULL:
        return "UNDEFINED";//
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.OTHER:
        return "UNDEFINED";//
    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:/*from w w  w. j a  va2 s. c om*/
        return "UNDEFINED";//
    }
}

From source file:org.brucalipto.sqlutil.SQLManager.java

/**
 * Method useful for SQL SELECT//from  w  ww .ja  va2  s . c  o  m
 * @param preparedStatement The prepared statement to execute
 * @param params List of {@link SQLParameter} to use to complete the prepared statement
 * @param outputSQLType A java.sql.Types type of return value
 * @return The {@link SPParameter} containing the returned value
 */
public SQLParameter simpleSelect(final String preparedStatement, SQLParameter[] params,
        final int outputSQLType) {
    final SQLParameter[] parameters;
    if (params == null) {
        parameters = new SQLParameter[0];
        log.debug("Going to execute a query without parameters.");
    } else {
        parameters = (SQLParameter[]) params.clone();
    }
    Connection dbConn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        if (this.dataSource != null) {
            dbConn = this.dataSource.getConnection();
        } else {
            dbConn = this.connection;
        }
        pstmt = dbConn.prepareStatement(preparedStatement);
        for (int i = 0; i < parameters.length; i++) {
            final SQLParameter param = parameters[i];
            log.debug((i + 1) + ") Going to add parameter " + param);
            final int sqlType = param.getSqlType();
            final Object paramValue = param.getValue();
            if (paramValue == null) {
                pstmt.setNull(i + 1, sqlType);
                continue;
            }
            switch (sqlType) {
            case Types.VARCHAR:
                pstmt.setString(i + 1, (String) paramValue);
                break;
            case Types.INTEGER:
                if (paramValue instanceof Integer) {
                    pstmt.setInt(i + 1, ((Integer) paramValue).intValue());
                } else if (paramValue instanceof Long) {
                    pstmt.setLong(i + 1, ((Long) paramValue).longValue());
                }
                break;
            case Types.DATE:
                pstmt.setDate(i + 1, (Date) paramValue);
                break;
            case Types.BOOLEAN:
                pstmt.setBoolean(i + 1, ((Boolean) paramValue).booleanValue());
                break;
            case Types.CHAR:
                pstmt.setString(i + 1, ((Character) paramValue).toString());
                break;
            case Types.DOUBLE:
                pstmt.setDouble(i + 1, ((Double) paramValue).doubleValue());
                break;
            case Types.FLOAT:
                pstmt.setFloat(i + 1, ((Float) paramValue).floatValue());
                break;
            case Types.TIMESTAMP:
                pstmt.setTimestamp(i + 1, (Timestamp) paramValue);
                break;
            default:
                pstmt.setObject(i + 1, paramValue);
                break;
            }
        }

        rs = pstmt.executeQuery();
        log.debug("Prepared statement '" + preparedStatement + "' succesfully executed!");
        while (rs.next()) {
            return new SQLParameter(outputSQLType, (Serializable) rs.getObject(1));
        }
        log.info("Prepared statement '" + preparedStatement + "' returned '0' rows");
    } catch (SQLException e) {
        log.error("Error executing prepared statement '" + preparedStatement + "'", e);
    } catch (Exception e) {
        log.error("Error executing prepared statement '" + preparedStatement + "'", e);
    } finally {
        closeResources(rs, pstmt, dbConn);
    }

    return new SQLParameter(outputSQLType, null);
}

From source file:org.easyrec.mahout.store.impl.MahoutDataModelMappingDAOMysqlImpl.java

@Override
public PreferenceArray getPreferencesForItem(int tenantId, Date cutoffDate, long itemID, int actionTypeId)
        throws TasteException {
    Object[] args = new Object[] { tenantId, cutoffDate, itemID, actionTypeId };
    int[] argTypes = new int[] { Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER };

    try {//from   w  w w . j  a  va 2s .c o  m
        return new GenericItemPreferenceArray(getJdbcTemplate().query(getPreferencesForItemQuery, args,
                argTypes, genericPreferenceRowMapper));
    } catch (EmptyResultDataAccessException e) {
        logger.warn("An error occurred!", e);
        throw new NoSuchItemException(itemID);
    }
}

From source file:jeeves.resources.dbms.Dbms.java

private Element buildElement(ResultSet rs, int col, String name, int type, Hashtable<String, String> formats)
        throws SQLException {
    String value = null;//from w w w  .j a va  2s. c  om

    switch (type) {
    case Types.DATE:
        Date date = rs.getDate(col + 1);
        if (date == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_DATE_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(date);
        }
        break;

    case Types.TIME:
        Time time = rs.getTime(col + 1);
        if (time == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIME_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(time);
        }
        break;

    case Types.TIMESTAMP:
        Timestamp timestamp = rs.getTimestamp(col + 1);
        if (timestamp == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIMESTAMP_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(timestamp);
        }
        break;

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        long l = rs.getLong(col + 1);
        if (rs.wasNull())
            value = null;
        else {
            String format = formats.get(name);
            if (format == null)
                value = l + "";
            else {
                DecimalFormat df = new DecimalFormat(format);
                value = df.format(l);
            }
        }
        break;

    case Types.DECIMAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
    case Types.NUMERIC:
        double n = rs.getDouble(col + 1);

        if (rs.wasNull())
            value = null;
        else {
            String format = formats.get(name);

            if (format == null) {
                value = n + "";

                // --- this fix is mandatory for oracle
                // --- that shit returns integers like xxx.0

                if (value.endsWith(".0"))
                    value = value.substring(0, value.length() - 2);
            } else {
                DecimalFormat df = new DecimalFormat(format);
                value = df.format(n);
            }
        }
        break;

    default:
        value = rs.getString(col + 1);
        if (value != null) {
            value = stripIllegalChars(value);
        }

        break;
    }
    return new Element(name).setText(value);
}

From source file:org.athenasource.framework.unidbi.Datatypes.java

/**
 * Returns the corresponding type as defined in {@link java.sql.Types} of the given UniDB datatype.
 * @param unidbType the UniDB datatype./*from  www  . ja v  a 2 s  .co m*/
 * @return the corresponding type as defined in {@link java.sql.Types} of the given UniDB datatype.
 */
public static int getSQLType(int unidbType) {
    switch (unidbType) {
    case BOOLEAN:
        return Types.TINYINT;
    case TINYINT:
        return Types.TINYINT;
    case SMALLINT:
        return Types.SMALLINT;
    case INTEGER:
        return Types.INTEGER;
    case BIGINT:
        return Types.BIGINT;
    case DECIMAL:
        return Types.DECIMAL;
    case REAL:
        return Types.REAL;
    case DOUBLE:
        return Types.DOUBLE;
    case CHAR:
        return Types.CHAR;
    case NCHAR:
        return Types.NCHAR;
    case VARCHAR:
        return Types.VARCHAR;
    case NVARCHAR:
        return Types.NVARCHAR;
    case CLOB: // Clob/NClob can be represented as String without any problem. - Oct 16, 2008.
        // but returns this type should be ok.
        return Types.CLOB;
    case NCLOB:
        return Types.NCLOB;
    case BLOB:
        return Types.BLOB;
    case TIMESTAMP:
        return Types.TIMESTAMP;
    default:
        throw new IllegalArgumentException("[!NO SUCH UNIDB DATA TYPE: " + unidbType + "]");
    }
}

From source file:jp.co.tis.gsp.tools.dba.dialect.OracleDialect.java

@Override
public int guessType(Connection conn, String schema, String tableName, String colName) throws SQLException {
    if (metaData == null) {
        metaData = conn.getMetaData();/*from   w  w w .  j a v  a2s  .c om*/
    }

    ResultSet rs = null;
    try {
        rs = metaData.getColumns(null, normalizeSchemaName(schema), normalizeTableName(tableName),
                normalizeColumnName(colName));

        if (!rs.next()) {
            throw new SQLException(tableName + "?" + colName + "????");
        }
        String type = rs.getString("TYPE_NAME");
        if (!isUsableType(type)) {
            System.err.println("[WARN] " + tableName + "." + colName + "  " + type
                    + "???????");
            return UN_USABLE_TYPE;
        } else if ("VARCHAR2".equals(type) || "NVARCHAR2".equals(type) || "NCHAR".equals(type)) {
            return Types.VARCHAR;
        } else if ("DATE".equals(type)) { // Types.TIMESTAMP????
            return Types.DATE;
        } else if (type.startsWith("TIMESTAMP")) { // TIMESTAMP(6)?Types.OTHER????
            return Types.TIMESTAMP;
        }
        return rs.getInt("DATA_TYPE");
    } finally {
        if (rs != null) {
            rs.close();
        }
    }
}