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:net.chrisrichardson.bankingExample.domain.jdbc.JdbcAccountDao.java

public void saveAccount(Account account) {
    int count = jdbcTemplate.update(
            "UPDATE BANK_ACCOUNT set accountId = ?, BALANCE = ?, overdraftPolicy = ?, dateOpened = ?, requiredYearsOpen = ?, limit = ? WHERE ACCOUNT_ID = ?",
            new Object[] { account.getAccountId(), account.getBalance(), account.getOverdraftPolicy(),
                    new Timestamp(account.getDateOpened().getTime()), account.getRequiredYearsOpen(),
                    account.getLimit(), account.getId() },
            new int[] { Types.VARCHAR, Types.DOUBLE, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE,
                    Types.INTEGER });
    Assert.isTrue(count == 1);/*from   w  ww. jav  a  2s.co  m*/

}

From source file:konditer.client.dao.CustomerDao.java

@Override
public void addCustomer(int customerId, int discountId, String customerFirstName) {
    String SQL_QUERY = "INSERT INTO customers ( CUSTOMER_ID, " + "DISCOUNT_ID, " + "CUSTOMER_LAST_NAME, "
            + "CUSTOMER_FIRST_NAME, " + "CUSTOMER_PARENT_NAME, " + "CUSTOMER_DATE_BORN, " + "CUSTOMER_INFO ) "
            + "VALUES (?,?,?,?,?,?,?)";
    int rowCount = 0;
    try {//w w w . j  a  v  a  2s . c o  m
        rowCount = jdbcTemplate.update(SQL_QUERY,
                new Object[] { customerId, discountId, "", customerFirstName, "", new Date(), "" },
                new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
                        Types.TIMESTAMP, Types.VARCHAR });
        Logger.getLogger(CustomerDao.class.getName()).log(Level.SEVERE,
                " : {0} .",
                rowCount + "\n" + customerDao.getCustomer(customerId).toString());
    } catch (DataAccessException e) {
        rowCount = 0;
        Logger.getLogger(CustomerDao.class.getName()).log(Level.SEVERE,
                "    .  ?: {0} .",
                rowCount);
    }
}

From source file:wzw.sql.ResultSetConverter.java

/**
 * ?/*from  w  w w .  j a v  a2 s  .  co  m*/
 * @param rs
 * @param type Listjava.sql.Types 
 * @return
 * @throws SQLException
 */
public static Object toType(ResultSet rs, int type) throws SQLException {

    if (rs.next()) { // run rs.next()
        switch (type) {
        case Types.INTEGER:
            return new Integer(rs.getInt(1));

        case Types.BIGINT:
            return new Long(rs.getLong(1));

        case Types.VARCHAR:
            return rs.getString(1);

        case Types.FLOAT:
            return new Float(rs.getFloat(1));

        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
            return new Double(rs.getDouble(1));

        case Types.TIMESTAMP:
            return rs.getTimestamp(1);

        case Types.DATE:
            return rs.getDate(1);

        case Types.TIME:
            return rs.getTime(1);

        default:
            return null;
        }
    }
    return null;

}

From source file:cherry.foundation.type.querydsl.LocalTimeTypeTest.java

@Test
public void testMisc() {

    LocalTimeType type = new LocalTimeType(Types.TIMESTAMP);
    assertEquals(1, type.getSQLTypes().length);
    assertEquals(Types.TIMESTAMP, type.getSQLTypes()[0]);

    assertEquals("12:34:56", type.getLiteral(new LocalTime(12, 34, 56)));
}

From source file:org.apache.kylin.jdbc.KylinClient.java

@SuppressWarnings("rawtypes")
public static Class convertType(int sqlType) {
    Class result = Object.class;

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        result = String.class;
        break;// w ww.j a va 2  s  . c o m
    case Types.NUMERIC:
    case Types.DECIMAL:
        result = BigDecimal.class;
        break;
    case Types.BIT:
        result = Boolean.class;
        break;
    case Types.TINYINT:
        result = Byte.class;
        break;
    case Types.SMALLINT:
        result = Short.class;
        break;
    case Types.INTEGER:
        result = Integer.class;
        break;
    case Types.BIGINT:
        result = Long.class;
        break;
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        result = Double.class;
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        result = Byte[].class;
        break;
    case Types.DATE:
        result = Date.class;
        break;
    case Types.TIME:
        result = Time.class;
        break;
    case Types.TIMESTAMP:
        result = Timestamp.class;
        break;
    default:
        //do nothing
        break;
    }

    return result;
}

From source file:cherry.foundation.type.querydsl.LocalDateTimeTypeTest.java

@Test
public void testMisc() {

    LocalDateTimeType type = new LocalDateTimeType(Types.TIMESTAMP);
    assertEquals(1, type.getSQLTypes().length);
    assertEquals(Types.TIMESTAMP, type.getSQLTypes()[0]);

    assertEquals("2015-01-23 12:34:56", type.getLiteral(new LocalDateTime(2015, 1, 23, 12, 34, 56)));
}

From source file:org.jumpmind.symmetric.DbExportImportTest.java

@Test
public void exportNullTimestampToCsv() throws Exception {
    ISymmetricEngine engine = getSymmetricEngine();
    IDatabasePlatform platform = engine.getDatabasePlatform();

    Table table = new Table("test_null_timestamp");
    table.addColumn(new Column("a", false, Types.TIMESTAMP, -1, -1));
    table.addColumn(new Column("b", false, Types.TIMESTAMP, -1, -1));
    platform.alterCaseToMatchDatabaseDefaultCase(table);
    platform.createTables(true, false, table);

    platform.getSqlTemplate().update("insert into test_null_timestamp values(null, null)");

    DbExport export = new DbExport(platform);
    export.setNoCreateInfo(true);//  w w w .j av  a 2s .c om
    export.setFormat(Format.CSV);

    String csv = export.exportTables(new Table[] { table });

    Assert.assertEquals("\"A\",\"B\"" + System.getProperty("line.separator") + ",", csv.trim().toUpperCase());

}

From source file:com.tesora.dve.common.TestDataGenerator.java

protected Object getColumnValue(ColumnMetadata cm) {
    Object cv = null;/* ww  w . jav  a  2  s  .  c o  m*/
    Calendar cal = Calendar.getInstance();

    switch (cm.getDataType()) {
    case Types.BIT:
    case Types.BOOLEAN:
        cv = Boolean.TRUE;
        break;
    case Types.BIGINT:
        cv = Long.MAX_VALUE;
        break;
    case Types.CHAR:
    case Types.VARCHAR:
        cv = StringUtils.left(baseString, cm.getSize());
        break;
    case Types.SMALLINT:
        cv = Short.MAX_VALUE;
        break;
    case Types.TINYINT:
        cv = Byte.MAX_VALUE;
        break;
    case Types.INTEGER:
        cv = Integer.MAX_VALUE;
        break;
    case Types.DOUBLE:
        cv = new Double(1234.5678); // TODO need to handle s,p
        break;
    case Types.FLOAT:
        cv = new Float(123.56); // TODO need to handle s,p
        break;
    case Types.DECIMAL:
        cv = new BigDecimal("12345.6789"); // TODO need to handle s,p
        break;
    case Types.DATE:
        cal.setTimeInMillis(123456789);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cv = cal.getTime();
        break;
    case Types.TIMESTAMP:
        cal.setTimeInMillis(123456789);
        cv = cal.getTime();
        break;
    case Types.TIME:
        cv = new Time(123456789);
        break;
    default:
        break;
    }

    return cv;
}

From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits.//ww  w .j  av  a2s.  c o  m
 */
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
        // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:org.silverpeas.core.test.util.SQLRequester.java

/**
 * Lists entities by executing the specified SQL query with the given parameters.
 * @param jdbcSqlQuery the {@link JdbcSqlQuery} instance.
 * @return a {@link List} of {@link ResultLine} instances.
 * @throws SQLException if an error occurs while executing the given {@link JdbcSqlQuery}.
 *//*from w w w  .j av a 2 s .c om*/
public static List<ResultLine> list(JdbcSqlQuery jdbcSqlQuery) throws SQLException {
    final List<Pair<String, Integer>> metaData = new ArrayList<>();
    return jdbcSqlQuery.execute(row -> {
        if (metaData.isEmpty()) {
            ResultSetMetaData rowMetaData = row.getMetaData();
            for (int i = 1; i <= rowMetaData.getColumnCount(); i++) {
                metaData.add(Pair.of(rowMetaData.getColumnName(i), rowMetaData.getColumnType(i)));
            }
        }
        SQLRequester.ResultLine line = new SQLRequester.ResultLine();
        for (int i = 1; i <= metaData.size(); i++) {
            Pair<String, Integer> columnNameAndType = metaData.get(i - 1);
            String name = columnNameAndType.getLeft().toUpperCase();
            final Object value;
            int sqlType = columnNameAndType.getRight();
            switch (sqlType) {
            case Types.BIGINT:
                value = row.getLong(i);
                break;
            case Types.DECIMAL:
                value = row.getBigDecimal(i);
                break;
            case Types.INTEGER:
                value = row.getInt(i);
                break;
            case Types.TIMESTAMP:
                value = row.getTimestamp(i);
                break;
            case Types.DATE:
                value = row.getDate(i);
                break;
            case Types.BOOLEAN:
                value = row.getBoolean(i);
                break;
            default:
                value = row.getString(i);
            }
            line.set(name, value);
        }
        return line;
    });
}