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:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static String getJavaDatatype(int colType) {

    switch (colType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return "java.lang.String";

    case Types.NUMERIC:
    case Types.DECIMAL:
        return "java.math.BigDecimal";

    case Types.BIT:
        return "boolean";

    case Types.TINYINT:
        return "byte";

    case Types.SMALLINT:
        return "short";

    case Types.INTEGER:
        return "int";

    case Types.BIGINT:
        return "long";

    case Types.REAL:
        return "float";

    case Types.FLOAT:
    case Types.DOUBLE:
        return "double";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "byte[]";

    case Types.DATE:
        return "java.sql.Date";

    case Types.TIME:
        return "java.sql.Time";

    case Types.TIMESTAMP:
        return "java.sql.Timestamp";

    case Types.OTHER:
        return "java.lang.Object";
    default://w  ww.java  2 s.  c  o m
        return null;
    }
}

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Retrieve the fully qualified java class name for the
 * supplied JDBC Types constant.//from   ww  w .j  a  v a2s . c om
 *
 * @param jdbcType The JDBC Types constant.
 * @return The fully qualified java class name as a <code>String</code>.
 */
static String getClassName(int jdbcType) {
    switch (jdbcType) {
    case java.sql.Types.BOOLEAN:
    case java.sql.Types.BIT:
        return "java.lang.Boolean";

    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
    case java.sql.Types.INTEGER:
        return "java.lang.Integer";

    case java.sql.Types.BIGINT:
        return "java.lang.Long";

    case java.sql.Types.NUMERIC:
    case java.sql.Types.DECIMAL:
        return "java.math.BigDecimal";

    case java.sql.Types.REAL:
        return "java.lang.Float";

    case java.sql.Types.FLOAT:
    case java.sql.Types.DOUBLE:
        return "java.lang.Double";

    case java.sql.Types.CHAR:
    case java.sql.Types.VARCHAR:
        return "java.lang.String";

    case java.sql.Types.BINARY:
    case java.sql.Types.VARBINARY:
        return "[B";

    case java.sql.Types.LONGVARBINARY:
    case java.sql.Types.BLOB:
        return "java.sql.Blob";

    case java.sql.Types.LONGVARCHAR:
    case java.sql.Types.CLOB:
        return "java.sql.Clob";

    case java.sql.Types.DATE:
        return "java.sql.Date";

    case java.sql.Types.TIME:
        return "java.sql.Time";

    case java.sql.Types.TIMESTAMP:
        return "java.sql.Timestamp";
    default:
        break;
    }

    return "java.lang.Object";
}

From source file:org.jumpmind.symmetric.db.ase.AseTriggerTemplate.java

@Override
protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
    String text = "";
    for (int i = 0; i < columns.length; i++) {
        text += "declare @" + prefix + "pk" + i + " ";
        switch (columns[i].getMappedTypeCode()) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
            // ASE does not support bigint
            text += "NUMERIC(18,0)\n";
            break;
        case Types.NUMERIC:
        case Types.DECIMAL:
            // Use same default scale and precision used by Sybase ASA
            // for a decimal with unspecified scale and precision.
            text += "decimal(30,6)\n";
            break;
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
            text += "float\n";
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            text += "varchar(1000)\n";
            break;
        case Types.DATE:
            text += "date\n";
            break;
        case Types.TIME:
            text += "time\n";
            break;
        case Types.TIMESTAMP:
            text += "datetime\n";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            text += "bit\n";
            break;
        case Types.CLOB:
            text += "varchar(32767)\n";
            break;
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            text += "varbinary(32767)\n";
            break;
        case Types.OTHER:
            text += "varbinary(32767)\n";
            break;
        default:/*  ww w  .  j ava2  s  .c  o  m*/
            if (columns[i].getJdbcTypeName() != null
                    && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) {
                text += "interval";
                break;
            }
            throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType());
        }
    }

    return text;
}

From source file:io.bibleget.BibleGetDB.java

private void listColNamesTypes(DatabaseMetaData dbMeta, ResultSet rs) {
    //System.out.println("After Table Creation: Table "+rs.getString("TABLE_NAME")+" exists !!");
    ResultSet cols;/*  ww w  . ja v a2s  .  c o m*/
    try {
        cols = dbMeta.getColumns(null, null, rs.getString("TABLE_NAME"), null);
        while (cols.next()) {
            //System.out.println(cols.getString("COLUMN_NAME"));
            colNames.add(cols.getString("COLUMN_NAME"));
            int dType = cols.getInt("DATA_TYPE");
            switch (dType) {
            case Types.VARCHAR:
                colDataTypes.add(String.class);
                break;
            case Types.INTEGER:
                colDataTypes.add(Integer.class);
                break;
            case Types.FLOAT:
                colDataTypes.add(Float.class);
                break;
            case Types.DOUBLE:
            case Types.REAL:
                colDataTypes.add(Double.class);
                break;
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                colDataTypes.add(java.sql.Date.class);
                break;
            case Types.BOOLEAN:
                colDataTypes.add(Boolean.class);
                break;
            default:
                colDataTypes.add(String.class);
                break;
            }
        }
    } catch (SQLException ex) {
        Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static boolean isPrimitiveType(int colType) {

    switch (colType) {

    case Types.BIT:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return true;

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return false;

    default:// ww w.  j  a  v a 2s. co m
        return false;
    }
}

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

@Override
public void insert(final Standplaats standplaats) throws DAOException {
    try {/*www.j av a2 s . c  o m*/
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection
                                .prepareStatement("insert into bag_standplaats (" + "bag_standplaats_id,"
                                        + "aanduiding_record_inactief," + "aanduiding_record_correctie,"
                                        + "officieel," + "standplaats_status," + "standplaats_geometrie,"
                                        + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid,"
                                        + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer,"
                                        + "bag_nummeraanduiding_id" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)");
                        ps.setLong(1, standplaats.getIdentificatie());
                        ps.setInt(2, standplaats.getAanduidingRecordInactief().ordinal());
                        ps.setLong(3, standplaats.getAanduidingRecordCorrectie());
                        ps.setInt(4, standplaats.getOfficieel().ordinal());
                        ps.setInt(5, standplaats.getStandplaatsStatus().ordinal());
                        ps.setString(6, standplaats.getStandplaatsGeometrie());
                        ps.setTimestamp(7,
                                new Timestamp(standplaats.getBegindatumTijdvakGeldigheid().getTime()));
                        if (standplaats.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(8, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(8,
                                    new Timestamp(standplaats.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(9, standplaats.getInOnderzoek().ordinal());
                        ps.setDate(10, new Date(standplaats.getDocumentdatum().getTime()));
                        ps.setString(11, standplaats.getDocumentnummer());
                        ps.setLong(12, standplaats.getHoofdAdres());
                        return ps;
                    }
                });
                insertNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaats);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting standplaats: " + standplaats.getIdentificatie(), e);
    }
}

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

@Override
public void insertConnectorMessage(ConnectorMessage connectorMessage, boolean storeMaps, boolean updateStats) {
    logger.debug(connectorMessage.getChannelId() + "/" + connectorMessage.getMessageId() + "/"
            + connectorMessage.getMetaDataId() + ": inserting connector message with" + (storeMaps ? "" : "out")
            + " maps");

    try {/*w w w  .  ja va  2  s.  c  o  m*/
        PreparedStatement statement = prepareStatement("insertConnectorMessage",
                connectorMessage.getChannelId());
        statement.setInt(1, connectorMessage.getMetaDataId());
        statement.setLong(2, connectorMessage.getMessageId());
        statement.setString(3, connectorMessage.getServerId());
        statement.setTimestamp(4, new Timestamp(connectorMessage.getReceivedDate().getTimeInMillis()));
        statement.setString(5, Character.toString(connectorMessage.getStatus().getStatusCode()));

        if (connectorMessage.getConnectorName() == null) {
            statement.setNull(6, Types.VARCHAR);
        } else {
            statement.setString(6, connectorMessage.getConnectorName());
        }

        statement.setInt(7, connectorMessage.getSendAttempts());

        if (connectorMessage.getSendDate() == null) {
            statement.setNull(8, Types.TIMESTAMP);
        } else {
            statement.setTimestamp(8, new Timestamp(connectorMessage.getSendDate().getTimeInMillis()));
        }

        if (connectorMessage.getResponseDate() == null) {
            statement.setNull(9, Types.TIMESTAMP);
        } else {
            statement.setTimestamp(9, new Timestamp(connectorMessage.getResponseDate().getTimeInMillis()));
        }

        statement.setInt(10, connectorMessage.getErrorCode());
        statement.setInt(11, connectorMessage.getChainId());
        statement.setInt(12, connectorMessage.getOrderId());
        statement.executeUpdate();

        if (storeMaps) {
            updateSourceMap(connectorMessage);
            updateMaps(connectorMessage);
        }

        updateErrors(connectorMessage);

        if (updateStats) {
            transactionStats.update(connectorMessage.getChannelId(), connectorMessage.getMetaDataId(),
                    connectorMessage.getStatus(), null);
        }
    } catch (SQLException e) {
        throw new DonkeyDaoException(e);
    }
}

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

@Override
public void insertWoonplaatsen(final List<Woonplaats> woonplaatsen) throws DAOException {
    try {/*from w ww  . j  a v a 2s.co  m*/
        jdbcTemplate.batchUpdate("insert into bag_woonplaats (" + "bag_woonplaats_id,"
                + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "woonplaats_naam,"
                + "woonplaats_geometrie," + "officieel," + "begindatum_tijdvak_geldigheid,"
                + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum,"
                + "bron_documentnummer," + "woonplaats_status" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)",
                new BatchPreparedStatementSetter() {
                    @Override
                    public void setValues(PreparedStatement ps, int i) throws SQLException {
                        ps.setLong(1, woonplaatsen.get(i).getIdentificatie());
                        ps.setInt(2, woonplaatsen.get(i).getAanduidingRecordInactief().ordinal());
                        ps.setLong(3, woonplaatsen.get(i).getAanduidingRecordCorrectie());
                        ps.setString(4, woonplaatsen.get(i).getWoonplaatsNaam());
                        ps.setString(5, woonplaatsen.get(i).getWoonplaatsGeometrie());
                        ps.setInt(6, woonplaatsen.get(i).getOfficieel().ordinal());
                        ps.setTimestamp(7,
                                new Timestamp(woonplaatsen.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                        if (woonplaatsen.get(i).getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(8, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(8, new Timestamp(
                                    woonplaatsen.get(i).getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(9, woonplaatsen.get(i).getInOnderzoek().ordinal());
                        ps.setDate(10, new Date(woonplaatsen.get(i).getDocumentdatum().getTime()));
                        ps.setString(11, woonplaatsen.get(i).getDocumentnummer());
                        ps.setInt(12, woonplaatsen.get(i).getWoonplaatsStatus().ordinal());
                    }

                    @Override
                    public int getBatchSize() {
                        return woonplaatsen.size();
                    }
                });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting woonplaatsen", e);
    }
}

From source file:org.easyrec.store.dao.web.impl.LoaderDAOMysqlImpl.java

@Override
public Operator addOperator(String id, String password, String firstName, String lastName, String email,
        String phone, String company, String address, String apiKey, String ip) {

    Object[] args = { id, password, firstName, lastName, email, phone, company, address, apiKey, ip, new Date(),
            true, 1 };//  w w  w .  jav  a2 s .c om

    int[] argTypes = { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.BOOLEAN,
            Types.INTEGER };

    try {
        getJdbcTemplate().update(SQL_ADD_OPERATOR, args, argTypes);

        return new Operator(id, password, firstName, lastName, email, phone, company, address, apiKey, ip, true,
                // active
                new Date().toString(), // creation date
                1, // acceslevel
                0, // login count
                null // last login date
        );
    } catch (Exception e) {
        logger.debug(e);
        e.printStackTrace();
        return null;
    }
}

From source file:ro.nextreports.engine.queryexec.QueryExecutor.java

private void setParameterValue(PreparedStatement pstmt, Class paramValueClass, Object paramValue, int index)
        throws SQLException, QueryException {

    // for "NOT IN (?)" setting null -> result is undeterminated
    // ParameterUtil.NULL was good only for list of strings (for NOT IN)!
    if (ParameterUtil.NULL.equals(paramValue)) {
        paramValue = null;/* www.j  ava  2 s .c om*/
    }
    if (paramValueClass.equals(Object.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.JAVA_OBJECT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setObject(index + 1, ((IdName) paramValue).getId());
            } else {
                pstmt.setObject(index + 1, paramValue);
            }
        }
    } else if (paramValueClass.equals(Boolean.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.BIT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setBoolean(index + 1, (Boolean) ((IdName) paramValue).getId());
            } else {
                pstmt.setBoolean(index + 1, (Boolean) paramValue);
            }
        }
    } else if (paramValueClass.equals(Byte.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.TINYINT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setByte(index + 1, (Byte) ((IdName) paramValue).getId());
            } else {
                pstmt.setByte(index + 1, (Byte) paramValue);
            }
        }
    } else if (paramValueClass.equals(Double.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.DOUBLE);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setDouble(index + 1, (Double) ((IdName) paramValue).getId());
            } else {
                pstmt.setDouble(index + 1, (Double) paramValue);
            }
        }
    } else if (paramValueClass.equals(Float.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.FLOAT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setFloat(index + 1, (Float) ((IdName) paramValue).getId());
            } else {
                pstmt.setFloat(index + 1, (Float) paramValue);
            }
        }
    } else if (paramValueClass.equals(Integer.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.INTEGER);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setObject(index + 1, ((IdName) paramValue).getId());
            } else {
                pstmt.setInt(index + 1, (Integer) paramValue);
            }
        }
    } else if (paramValueClass.equals(Long.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.BIGINT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setLong(index + 1, (Long) ((IdName) paramValue).getId());
            } else {
                pstmt.setLong(index + 1, (Long) paramValue);
            }
        }
    } else if (paramValueClass.equals(Short.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.SMALLINT);
        } else {
            if (paramValue instanceof IdName) {
                pstmt.setShort(index + 1, (Short) ((IdName) paramValue).getId());
            } else {
                pstmt.setShort(index + 1, (Short) paramValue);
            }
        }

        //@todo    
        // ParameterUtil -> values are taken from dialect (where there is no BigDecimal yet!)
        // or from meta  data
    } else if (paramValueClass.equals(BigDecimal.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.DECIMAL);
        } else {
            if (paramValue instanceof IdName) {
                Serializable ser = ((IdName) paramValue).getId();
                if (ser instanceof BigDecimal) {
                    pstmt.setBigDecimal(index + 1, (BigDecimal) (ser));
                } else {
                    pstmt.setInt(index + 1, (Integer) (ser));
                }
            } else {
                // a simple value cannot be cast to BigDecimal!                   
                pstmt.setObject(index + 1, paramValue);
            }
        }
    } else if (paramValueClass.equals(BigInteger.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.BIGINT);
        } else {
            if (paramValue instanceof IdName) {
                Serializable ser = ((IdName) paramValue).getId();
                if (ser instanceof BigInteger) {
                    pstmt.setBigDecimal(index + 1, new BigDecimal((BigInteger) (ser)));
                } else if (ser instanceof BigDecimal) {
                    pstmt.setBigDecimal(index + 1, (BigDecimal) (ser));
                } else {
                    pstmt.setInt(index + 1, (Integer) (ser));
                }
            } else {
                // a simple value cannot be cast to BigDecimal!                   
                pstmt.setObject(index + 1, paramValue);
            }
        }
    } else if (paramValueClass.equals(String.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.VARCHAR);
        } else {
            if (paramValue instanceof IdName) {
                if (((IdName) paramValue).getId() == null) {
                    pstmt.setNull(index + 1, Types.VARCHAR);
                } else {
                    pstmt.setString(index + 1, ((IdName) paramValue).getId().toString());
                }
            } else {
                pstmt.setString(index + 1, paramValue.toString());
            }
        }
    } else if (paramValueClass.equals(Date.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.DATE);
        } else {
            if (paramValue instanceof IdName) {
                Serializable obj = ((IdName) paramValue).getId();
                Date date;
                if (obj instanceof String) {
                    try {
                        date = IdNameRenderer.sdf.parse((String) obj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        date = new Date();
                    }
                } else {
                    date = (Date) obj;
                }
                pstmt.setDate(index + 1, new java.sql.Date(date.getTime()));
            } else {
                pstmt.setDate(index + 1, new java.sql.Date(((Date) paramValue).getTime()));
            }
        }
    } else if (paramValueClass.equals(Timestamp.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.TIMESTAMP);
        } else {
            if (paramValue instanceof IdName) {
                Serializable obj = ((IdName) paramValue).getId();
                Date date;
                if (obj instanceof String) {
                    try {
                        date = IdNameRenderer.sdf.parse((String) obj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        date = new Date();
                    }
                } else {
                    date = (Date) obj;
                }

                pstmt.setTimestamp(index + 1, new Timestamp(date.getTime()));
            } else {
                pstmt.setTimestamp(index + 1, new Timestamp(((Date) paramValue).getTime()));
            }
        }
    } else if (paramValueClass.equals(Time.class)) {
        if (paramValue == null) {
            pstmt.setNull(index + 1, Types.TIME);
        } else {
            if (paramValue instanceof IdName) {
                Serializable obj = ((IdName) paramValue).getId();
                Date date;
                if (obj instanceof String) {
                    try {
                        date = IdNameRenderer.sdf.parse((String) obj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        date = new Date();
                    }
                } else {
                    date = (Date) obj;
                }
                pstmt.setTime(index + 1, new Time(date.getTime()));
            } else {
                pstmt.setTime(index + 1, new Time(((Date) paramValue).getTime()));
            }
        }
    } else {
        throw new QueryException("Parameter type " + paramValueClass.getName() + " not supported in query");
    }

    // for logSql()
    statementParameters.put(index, paramValue);
}