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.springframework.batch.core.repository.dao.JdbcJobExecutionDao.java

/**
 *
 * SQL implementation using Sequences via the Spring incrementer
 * abstraction. Once a new id has been obtained, the JobExecution is saved
 * via a SQL INSERT statement.//from   ww  w. j a  v  a2  s. co m
 *
 * @see JobExecutionDao#saveJobExecution(JobExecution)
 * @throws IllegalArgumentException if jobExecution is null, as well as any
 * of it's fields to be persisted.
 */
@Override
public void saveJobExecution(JobExecution jobExecution) {

    validateJobExecution(jobExecution);

    jobExecution.incrementVersion();

    jobExecution.setId(jobExecutionIncrementer.nextLongValue());
    Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(),
            jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(),
            jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(),
            jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(),
            jobExecution.getJobConfigurationName() };
    getJdbcTemplate().update(getQuery(SAVE_JOB_EXECUTION), parameters,
            new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR,
                    Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP,
                    Types.VARCHAR });

    insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters());
}

From source file:com.connsec.authentication.AcceptJdbcUsersAuthenticationHandler.java

/**
  * login log write to log db//from w w w.  j  a v a  2  s . c  om
  * @param uid
  * @param j_username
  * @param type
  * @param code
  * @param message
  */
public boolean insertLoginHistory(UserInfo userInfo, String type, String provider, String code,
        String message) {
    Date loginDate = new Date();
    String sessionId = WebContext.genId();
    WebContext.setAttribute(WebConstants.CURRENT_USER_SESSION_ID, sessionId);
    String ipAddress = WebContext.getRequestIpAddress();
    String platform = "";
    String browser = "";
    String userAgent = WebContext.getRequest().getHeader("User-Agent");
    String[] arrayUserAgent = null;
    if (userAgent.indexOf("MSIE") > 0) {
        arrayUserAgent = userAgent.split(";");
        browser = arrayUserAgent[1].trim();
        platform = arrayUserAgent[2].trim();
    } else if (userAgent.indexOf("Trident") > 0) {
        arrayUserAgent = userAgent.split(";");
        browser = "MSIE/" + arrayUserAgent[3].split("\\)")[0];
        ;
        platform = arrayUserAgent[0].split("\\(")[1];
    } else if (userAgent.indexOf("Chrome") > 0) {
        arrayUserAgent = userAgent.split(" ");
        //browser=arrayUserAgent[8].trim();
        for (int i = 0; i < arrayUserAgent.length; i++) {
            if (arrayUserAgent[i].contains("Chrome")) {
                browser = arrayUserAgent[i].trim();
                browser = browser.substring(0, browser.indexOf('.'));
            }
        }
        platform = (arrayUserAgent[1].substring(1) + " " + arrayUserAgent[2] + " "
                + arrayUserAgent[3].substring(0, arrayUserAgent[3].length() - 1)).trim();
    } else if (userAgent.indexOf("Firefox") > 0) {
        arrayUserAgent = userAgent.split(" ");
        for (int i = 0; i < arrayUserAgent.length; i++) {
            if (arrayUserAgent[i].contains("Firefox")) {
                browser = arrayUserAgent[i].trim();
                browser = browser.substring(0, browser.indexOf('.'));
            }
        }
        platform = (arrayUserAgent[1].substring(1) + " " + arrayUserAgent[2] + " "
                + arrayUserAgent[3].substring(0, arrayUserAgent[3].length() - 1)).trim();

    }

    jdbcTemplate.update(HISTORY_LOGIN_INSERT_STATEMENT,
            new Object[] { WebContext.genId(), sessionId, userInfo.getId(), userInfo.getUsername(),
                    userInfo.getDisplayName(), type, message, code, provider, ipAddress, browser, platform,
                    "Browser", loginDate },
            new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
                    Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
                    Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP });

    userInfo.setLastLoginTime(new SimpleDateFormat(FORMAT_DATE_YYYY_MM_DD_HH_MM_SS).format(loginDate));

    jdbcTemplate.update(LOGIN_USERINFO_UPDATE_STATEMENT,
            new Object[] { loginDate, ipAddress, userInfo.getLoginCount() + 1, userInfo.getId() },
            new int[] { Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.VARCHAR });

    return true;
}

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

@Override
public int updateCustomer(int customerId, int newDiscountId, String newCustomerLastName,
        String newCustomerFirstName, String newCustomerParentName, Date newCustomerDateBorn,
        String newCustomerInfo) {
    System.out.println("  CustomerDao.updateCustomer c : newCustomerDateBorn="
            + newCustomerDateBorn);/*w w  w.ja va 2  s.  com*/
    String SQL_QUERY = "UPDATE customers " + "SET DISCOUNT_ID = ?, " + "CUSTOMER_LAST_NAME = ?, "
            + "CUSTOMER_FIRST_NAME = ?, " + "CUSTOMER_PARENT_NAME = ?, " + "CUSTOMER_DATE_BORN = ?, "
            + "CUSTOMER_INFO = ? " + "WHERE CUSTOMER_ID = ?";
    int rowCount = 0;
    try {
        rowCount = jdbcTemplate.update(SQL_QUERY,
                new Object[] { newDiscountId, newCustomerLastName, newCustomerFirstName, newCustomerParentName,
                        newCustomerDateBorn, newCustomerInfo, customerId },
                new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP,
                        Types.VARCHAR, Types.INTEGER });
        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);
    }
    return rowCount;
}

From source file:CSVWriter.java

private static String getColumnValue(ResultSet rs, int colType, int colIndex)
    throws SQLException, IOException {

  String value = "";
      /*from  w  ww.  j  a v a  2 s. c  om*/
switch (colType)
{
  case Types.BIT:
    Object bit = rs.getObject(colIndex);
    if (bit != null) {
      value = String.valueOf(bit);
    }
  break;
  case Types.BOOLEAN:
    boolean b = rs.getBoolean(colIndex);
    if (!rs.wasNull()) {
      value = Boolean.valueOf(b).toString();
    }
  break;
  case Types.CLOB:
    Clob c = rs.getClob(colIndex);
    if (c != null) {
      value = read(c);
    }
  break;
  case Types.BIGINT:
  case Types.DECIMAL:
  case Types.DOUBLE:
  case Types.FLOAT:
  case Types.REAL:
  case Types.NUMERIC:
    BigDecimal bd = rs.getBigDecimal(colIndex);
    if (bd != null) {
      value = "" + bd.doubleValue();
    }
  break;
  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
    int intValue = rs.getInt(colIndex);
    if (!rs.wasNull()) {
      value = "" + intValue;
    }
  break;
  case Types.JAVA_OBJECT:
    Object obj = rs.getObject(colIndex);
    if (obj != null) {
      value = String.valueOf(obj);
    }
  break;
  case Types.DATE:
    java.sql.Date date = rs.getDate(colIndex);
    if (date != null) {
      value = DATE_FORMATTER.format(date);;
    }
  break;
  case Types.TIME:
    Time t = rs.getTime(colIndex);
    if (t != null) {
      value = t.toString();
    }
  break;
  case Types.TIMESTAMP:
    Timestamp tstamp = rs.getTimestamp(colIndex);
    if (tstamp != null) {
      value = TIMESTAMP_FORMATTER.format(tstamp);
    }
  break;
  case Types.LONGVARCHAR:
  case Types.VARCHAR:
  case Types.CHAR:
    value = rs.getString(colIndex);
  break;
  default:
    value = "";
}

    
if (value == null)
{
  value = "";
}
    
return value;
      
}

From source file:com.gs.obevo.db.apps.reveng.CsvStaticDataWriter.java

private void writeTable(DbPlatform dbtype, PhysicalSchema schema, String tableName, File directory,
        MutableSet<String> updateTimeColumns, final CSVFormat csvFormat) {
    directory.mkdirs();/*from w  ww .  j a v  a 2s  .co  m*/
    DaTable table = this.metadataManager.getTableInfo(schema.getPhysicalName(), tableName,
            new DaSchemaInfoLevel().setRetrieveTableColumns(true));
    if (table == null) {
        System.out.println("No data found for table " + tableName);
        return;
    }
    MutableList<String> columnNames = table.getColumns().collect(DaNamedObject.TO_NAME).toList();
    final String updateTimeColumnForTable = updateTimeColumns == null ? null
            : updateTimeColumns.detect(Predicates.in(columnNames));
    if (updateTimeColumnForTable != null) {
        columnNames.remove(updateTimeColumnForTable);
        System.out.println("Will mark " + updateTimeColumnForTable + " as an updateTimeColumn on this table");
    }

    final File tableFile = new File(directory, tableName + ".csv");
    final String selectSql = String.format("SELECT %s FROM %s%s", columnNames.makeString(", "),
            dbtype.getSchemaPrefix(schema), tableName);

    // using the jdbcTempate and ResultSetHandler to avoid sql-injection warnings in findbugs
    sqlExecutor.executeWithinContext(schema, new Procedure<Connection>() {
        @Override
        public void value(Connection conn) {
            sqlExecutor.getJdbcTemplate().query(conn, selectSql, new ResultSetHandler<Void>() {
                @Override
                public Void handle(ResultSet rs) throws SQLException {
                    CSVPrinter writer = null;
                    try {
                        FileWriter fw = new FileWriter(tableFile);
                        writer = new CSVPrinter(fw, csvFormat);

                        if (updateTimeColumnForTable != null) {
                            String metadataLine = String.format("//// METADATA %s=\"%s\"",
                                    TextMarkupDocumentReader.ATTR_UPDATE_TIME_COLUMN, updateTimeColumnForTable);
                            fw.write(metadataLine + "\n"); // writing using the FileWriter directly to avoid having the quotes
                            // delimited
                        }

                        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                        DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

                        int columnCount = rs.getMetaData().getColumnCount();

                        // print headers
                        for (int i = 1; i <= columnCount; ++i) {
                            writer.print(rs.getMetaData().getColumnName(i));
                        }
                        writer.println();

                        while (rs.next()) {
                            for (int i = 1; i <= columnCount; ++i) {
                                Object object = rs.getObject(i);
                                if (object != null) {
                                    switch (rs.getMetaData().getColumnType(i)) {
                                    case Types.DATE:
                                        object = dateFormat.format(object);
                                        break;
                                    case Types.TIMESTAMP:
                                        object = dateTimeFormat.format(object);
                                        break;
                                    case Types.LONGVARCHAR:
                                    case Types.VARCHAR:
                                    case Types.CHAR:
                                        // escape the string text if declared so that the input CSV can also handle the escapes
                                        if (csvFormat.getEscapeCharacter() != null
                                                && object instanceof String) {
                                            object = ((String) object).replace(
                                                    "" + csvFormat.getEscapeCharacter(),
                                                    "" + csvFormat.getEscapeCharacter()
                                                            + csvFormat.getEscapeCharacter());
                                        }
                                        break;
                                    }
                                }
                                writer.print(object);
                            }

                            writer.println();
                        }

                        writer.flush();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } finally {
                        IOUtils.closeQuietly(writer);
                    }

                    return null;
                }
            });
        }
    });

    int blankFileSize = updateTimeColumnForTable == null ? 1 : 2;

    if (!tableFile.canRead() || FileUtilsCobra.readLines(tableFile).size() <= blankFileSize) {
        System.out.println("No data found for table " + tableName + "; will clean up file");
        FileUtils.deleteQuietly(tableFile);
    }
}

From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java

private void initDialect(DatabaseIdiom idiom) {
    databaseIdiom = idiom;// w  w w .j  av  a 2 s .c o  m
    try {
        addTranslation("bigint", idiom.getTypeName(Types.BIGINT));
        addTranslation("binary", idiom.getTypeName(Types.BINARY));
        addTranslation("bit", idiom.getTypeName(Types.BIT));
        addTranslation("blob", idiom.getTypeName(Types.BLOB));
        addTranslation("boolean", idiom.getTypeName(Types.BOOLEAN));
        addTranslation("char", idiom.getTypeName(Types.CHAR));
        addTranslation("clob", idiom.getTypeName(Types.CLOB));
        addTranslation("date", idiom.getTypeName(Types.DATE));
        addTranslation("decimal", idiom.getTypeName(Types.DECIMAL));
        addTranslation("double", idiom.getTypeName(Types.DOUBLE));
        addTranslation("float", idiom.getTypeName(Types.FLOAT));
        addTranslation("integer", idiom.getTypeName(Types.INTEGER));
        addTranslation("longnvarchar", idiom.getTypeName(Types.LONGNVARCHAR));
        addTranslation("longvarbinary", idiom.getTypeName(Types.LONGVARBINARY));
        addTranslation("longvarchar", idiom.getTypeName(Types.LONGVARCHAR));
        addTranslation("nchar", idiom.getTypeName(Types.NCHAR));
        addTranslation("nclob", idiom.getTypeName(Types.NCLOB));
        addTranslation("numeric", idiom.getTypeName(Types.NUMERIC));
        addTranslation("nvarchar", idiom.getTypeName(Types.NVARCHAR));
        addTranslation("real", idiom.getTypeName(Types.REAL));
        addTranslation("smallint", idiom.getTypeName(Types.SMALLINT));
        addTranslation("time", idiom.getTypeName(Types.TIME));
        addTranslation("timestamp", idiom.getTypeName(Types.TIMESTAMP));
        addTranslation("tinyint", idiom.getTypeName(Types.TINYINT));
        addTranslation("varbinary", idiom.getTypeName(Types.VARBINARY));

        databaseIdiom.initDialect(translations, workarounds);
        // Ignore autogenerated ID's
        addWorkaround("generated always as identity", "");
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.jasig.ssp.util.importer.job.validation.map.metadata.database.MapColumnMetadata.java

public Object convertValueToType(String columnValue, MapReference mapReference,
        DatabaseConstraintMapValidationContext validation) {
    Object propertyValue = null;/*w w  w . j ava  2 s .  c  o m*/
    String typeAsString = "";
    if (columnValue != null) {
        try {
            switch (javaSqlType) {
            case Types.BIGINT:
                typeAsString = "BIGINT";
                propertyValue = Long.parseLong(columnValue);
                break;
            case Types.INTEGER:
                typeAsString = "INTEGER";
                propertyValue = Integer.parseInt(columnValue);
                break;
            case Types.DECIMAL:
                typeAsString = "DECIMAL";
            case Types.DOUBLE:
                typeAsString = "DOUBLE";
            case Types.FLOAT:
                typeAsString = "FLOAT";
            case Types.NUMERIC:
                typeAsString = "NUMERIC";
                propertyValue = new BigDecimal(columnValue);
                break;

            case Types.DATE:
                typeAsString = "DATE";
                propertyValue = DateUtils.parseDateStrictly(columnValue, DATE_PATTERNS);
                break;
            case Types.TIMESTAMP:
                typeAsString = "TIMESTAMP";
                propertyValue = new java.sql.Timestamp(Long.getLong(columnValue));
                break;
            case Types.TIME:
                typeAsString = "TIME";
                propertyValue = new Time(DateUtils.parseDateStrictly(columnValue, TIME_PATTERNS).getTime());
                break;
            default:
                typeAsString = javaSqlType.toString();
                propertyValue = columnValue;
                break;

            }
        } catch (Exception exception) {
            validation.addViolation(new UnableToParseMapViolation(mapReference, columnValue, typeAsString));
            propertyValue = columnValue;
        }

    }
    return propertyValue;
}

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

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING:/* w w  w  .  ja v  a 2s.  co m*/
        if (type.isUnconstrained()) {
            return jdbcInfo("NVARCHAR(4000)", Types.VARCHAR);
        } else if (type.isClob() || type.length > 4000) {
            return jdbcInfo("NVARCHAR(MAX)", Types.CLOB);
        } else {
            return jdbcInfo("NVARCHAR(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("BIT", Types.BIT);
    case LONG:
        return jdbcInfo("BIGINT", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("DATETIME", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("NVARCHAR(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        switch (idType) {
        case VARCHAR:
            return jdbcInfo("NVARCHAR(36)", Types.VARCHAR);
        case SEQUENCE:
            return jdbcInfo("BIGINT", Types.BIGINT);
        }
    case SYSNAME:
    case SYSNAMEARRAY:
        return jdbcInfo("NVARCHAR(256)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("TINYINT", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("INT", Types.INTEGER);
    case AUTOINC:
        return jdbcInfo("INT IDENTITY", Types.INTEGER);
    case FTINDEXED:
        throw new AssertionError(type);
    case FTSTORED:
        return jdbcInfo("NVARCHAR(MAX)", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("SMALLINT", Types.SMALLINT);
    case CLUSTERFRAGS:
        return jdbcInfo("NVARCHAR(4000)", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

From source file:org.apache.syncope.core.persistence.jpa.content.XMLContentExporter.java

private String getValues(final ResultSet rs, final String columnName, final Integer columnType)
        throws SQLException {

    String res = null;//  w  ww  . j  a v a 2s .  c  om

    try {
        switch (columnType) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            final InputStream is = rs.getBinaryStream(columnName);
            if (is != null) {
                res = DatatypeConverter.printHexBinary(IOUtils.toByteArray(is));
            }
            break;

        case Types.BLOB:
            final Blob blob = rs.getBlob(columnName);
            if (blob != null) {
                res = DatatypeConverter.printHexBinary(IOUtils.toByteArray(blob.getBinaryStream()));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            if (rs.getBoolean(columnName)) {
                res = "1";
            } else {
                res = "0";
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnName);
            if (timestamp != null) {
                res = FormatUtils.format(new Date(timestamp.getTime()));
            }
            break;

        default:
            res = rs.getString(columnName);
        }
    } catch (IOException e) {
        LOG.error("Error retrieving hexadecimal string", e);
    }

    return res;
}

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

@Override
public int updateOrdere(int orderId, int newCustomerId, int newDeliveryId, int newOrderStatusId,
        Date newOrderDateIncome, Date newOrderDateEnd, double orderCakePrice, double newOrderDeliveryPrice,
        double newOrderWeight, String orderInsidesId, String newOrderInfo) {
    String SQL_QUERY = "UPDATE orders " + "SET CUSTOMER_ID = ?, " + "DELIVERY_ID = ?, "
            + "ORDER_STATUS_ID = ?, " + "ORDER_DATE_INCOME = ?, " + "ORDER_DATE_END = ?, " + "ORDER_INFO = ?, "
            + "ORDER_CAKE_PRICE = ?, " + "ORDER_DELIVERY_PRICE = ?, " + "ORDER_WEIGHT = ?, "
            + "ORDER_INSIDES_ID = ? " + "WHERE ORDER_ID = ? ";
    int rowCount = 0;
    rowCount = jdbcTemplate.update(SQL_QUERY,
            new Object[] { newCustomerId, newDeliveryId, newOrderStatusId, newOrderDateIncome, newOrderDateEnd,
                    newOrderInfo, orderCakePrice, newOrderDeliveryPrice, newOrderWeight, orderInsidesId,
                    orderId },/*from  ww  w . j a v  a 2 s  .com*/
            new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP,
                    Types.VARCHAR, Types.DOUBLE, Types.DOUBLE, Types.DOUBLE, Types.VARCHAR, Types.INTEGER });
    Logger.getLogger(OrdereDao.class.getName()).log(Level.SEVERE,
            " : {0} .", rowCount);
    return rowCount;
}