Example usage for java.sql ResultSet getTimestamp

List of usage examples for java.sql ResultSet getTimestamp

Introduction

In this page you can find the example usage for java.sql ResultSet getTimestamp.

Prototype

java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming language.

Usage

From source file:dsd.dao.ParsedInputFilesDAO.java

public static long GetMaxTimestamp(eFileType fileType) {
    long timestamp = 0;
    try {// w ww.j a va  2  s  .  co m
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            Object[] parameters = new Object[1];
            parameters[0] = new Integer(fileType.getCode());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, " max(timestamp) ", " type = ? ", "",
                    con, parameters);
            while (results.next()) {
                timestamp = results.getTimestamp(1).getTime();
            }
        } catch (Exception exc) {
            //            exc.printStackTrace();
            timestamp = 0;
        }
        con.close();
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return timestamp;
}

From source file:dsd.dao.WorstCaseDAO.java

public static long GetMaxTimestamp(boolean traffic, boolean debris) {
    long timestamp = 0;
    try {/*w  w w  .ja v  a  2 s  .  c o  m*/
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            String tableName = GetTableNameForDataType(traffic, debris);
            ResultSet results = DAOProvider.SelectTableSecure(tableName, " max(timestamp) ", "", "", con, null);
            while (results.next()) {
                timestamp = results.getTimestamp(1).getTime();
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return timestamp;
}

From source file:com.nortal.petit.converter.util.ResultSetHelper.java

private static Long getMilliseconds(ResultSet rs, ColumnPosition column) throws SQLException {
    Timestamp timestamp = column.isNamed ? rs.getTimestamp(column.getName())
            : rs.getTimestamp(column.getIndex());
    return timestamp == null ? null : timestamp.getTime();
}

From source file:dsd.dao.CalculatedDataDAO.java

public static long GetMaxTimestamp(eCalculatedDataType eDataType) {
    long timestamp = 0;
    try {//from w  w w  .  j  a  v a  2s. c  om
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            String tableName = GetTableNameForDataType(eDataType);
            ResultSet results = DAOProvider.SelectTableSecure(tableName, " max(timestamp) ", "", "", con, null);
            while (results.next()) {
                timestamp = results.getTimestamp(1).getTime();
            }
        } catch (Exception exc) {
            //            exc.printStackTrace();
            timestamp = 0;
        }
        con.close();
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return timestamp;
}

From source file:com.example.querybuilder.server.Jdbc.java

public static Date getTimestamp(ResultSet resultSet, int columnNumber) {
    try {// www.j  a v a 2 s  .co m
        return resultSet.getTimestamp(columnNumber);
    } catch (SQLException e) {
        throw new SqlRuntimeException(e);
    }
}

From source file:com.silverpeas.gallery.dao.OrderDAO.java

/**
 * Finds orders from the specified criteria.
 * @param con//from ww w . j av a  2s  .c om
 * @param criteria
 * @return a list of orders, empty if no order found.
 */
public static List<Order> findByCriteria(final Connection con, MediaOrderCriteria criteria)
        throws SQLException {

    MediaOrderSQLQueryBuilder queryBuilder = new MediaOrderSQLQueryBuilder();
    criteria.processWith(queryBuilder);

    Pair<String, List<Object>> queryBuild = queryBuilder.result();

    return queryBuilder.orderingResult(
            select(con, queryBuild.getLeft(), queryBuild.getRight(), new SelectResultRowProcessor<Order>() {

                @Override
                protected Order currentRow(final int rowIndex, final ResultSet rs) throws SQLException {
                    Order order = new Order(rs.getString(1));
                    order.setUserId(rs.getString(2));
                    order.setInstanceId(rs.getString(3));
                    order.setCreationDate(rs.getTimestamp(4));
                    order.setProcessDate(rs.getTimestamp(5));
                    order.setProcessUserId(rs.getString(6));
                    order.setRows(getAllOrderDetails(con, order.getOrderId()));
                    return order;
                }
            }));
}

From source file:com.silverpeas.gallery.dao.OrderDAO.java

/**
 * Gets all medias of an order./*from w  w  w  .ja  v a 2  s.com*/
 * @param con
 * @param orderId
 * @return
 * @throws SQLException
 */
public static List<OrderRow> getAllOrderDetails(Connection con, final String orderId) throws SQLException {
    return select(con,
            "select mediaId, instanceId, downloadDate, downloadDecision  from SC_Gallery_OrderDetail "
                    + "where orderId = ?",
            orderId, new SelectResultRowProcessor<OrderRow>() {

                @Override
                protected OrderRow currentRow(final int rowIndex, final ResultSet rs) throws SQLException {
                    String mediaId = rs.getString(1);
                    String instanceId = rs.getString(2);
                    OrderRow orderRow = new OrderRow(orderId, mediaId, instanceId);
                    orderRow.setDownloadDate(rs.getTimestamp(3));
                    orderRow.setDownloadDecision(rs.getString(4));
                    return orderRow;
                }
            });
}

From source file:las.DBConnector.java

public static ArrayList<Transaction> getTransactionTable() throws SQLException {
    ArrayList<Transaction> table = new ArrayList<>();
    String data = "SELECT * FROM Transactions";
    PreparedStatement pt = conn.prepareStatement(data);
    ResultSet rs = pt.executeQuery();
    while (rs.next()) {
        table.add(new Transaction(rs.getInt("MEMBER_ID"), rs.getInt("ITEM_ID"),
                rs.getTimestamp("TRANSACTION_TIME")));
    }//from   w  w w .  j a v a  2s .  c  o  m

    return table;
}

From source file:com.sap.dirigible.repository.db.dao.DBMapper.java

/**
 * ResultSet current row to DB Repository transformation
 * /*  w w  w. j ava  2 s.  c om*/
 * @param repository
 * @param resultSet
 * @return
 * @throws SQLException
 * @throws DBBaseException
 */
static DBObject dbToObject(DBRepository repository, ResultSet resultSet) throws SQLException, DBBaseException {

    String name = resultSet.getString(FILE_NAME);
    String path = resultSet.getString(FILE_PATH);
    int type = resultSet.getInt(FILE_TYPE);
    String content = resultSet.getString(FILE_CONTENT_TYPE);
    String createdBy = resultSet.getString(FILE_CREATED_BY);
    Date createdAt = new Date(resultSet.getTimestamp(FILE_CREATED_AT).getTime());
    String modifiedBy = resultSet.getString(FILE_MODIFIED_BY);
    Date modifiedAt = new Date(resultSet.getTimestamp(FILE_MODIFIED_AT).getTime());

    DBObject dbObject = null;
    if (type == OBJECT_TYPE_FOLDER) {
        dbObject = new DBFolder(repository);
    } else if (type == OBJECT_TYPE_DOCUMENT) {
        dbObject = new DBFile(repository, false, content);
    } else if (type == OBJECT_TYPE_BINARY) {
        dbObject = new DBFile(repository, true, content);
    } else {
        throw new DBBaseException(Messages.getString("DBMapper.THE_OBJECT_IS_UNKNOWN")); //$NON-NLS-1$
    }

    dbObject.setName(name);
    dbObject.setPath(path);
    dbObject.setCreatedBy(createdBy);
    dbObject.setCreatedAt(new java.util.Date(createdAt.getTime()));
    dbObject.setModifiedBy(modifiedBy);
    dbObject.setModifiedAt(new java.util.Date(modifiedAt.getTime()));

    return dbObject;
}

From source file:jdbc.JdbcUtils.java

/**
 * Retrieve a JDBC column value from a ResultSet, using the most appropriate
 * value type. The returned value should be a detached value object, not
 * having any ties to the active ResultSet: in particular, it should not be
 * a Blob or Clob object but rather a byte array respectively String
 * representation.//from w w w .j  av a  2  s  .c  om
 * <p>
 * Uses the <code>getObject(index)</code> method, but includes additional
 * "hacks" to get around Oracle 10g returning a non-standard object for its
 * TIMESTAMP datatype and a <code>java.sql.Date</code> for DATE columns
 * leaving out the time portion: These columns will explicitly be extracted
 * as standard <code>java.sql.Timestamp</code> object.
 * 
 * @param rs
 *            is the ResultSet holding the data
 * @param index
 *            is the column index
 * @return the value object
 * @see java.sql.Blob
 * @see java.sql.Clob
 * @see java.sql.Timestamp
 * @see oracle.sql.TIMESTAMP
 */
public static Object getResultSetValue(ResultSet rs, int index) throws SQLException {
    Object obj = rs.getObject(index);
    if (obj instanceof Blob) {
        obj = rs.getBytes(index);
    } else if (obj instanceof Clob) {
        obj = rs.getString(index);
    } else if (obj != null && obj.getClass().getName().startsWith("oracle.sql.TIMESTAMP")) {
        obj = rs.getTimestamp(index);
    } else if (obj != null && obj.getClass().getName().startsWith("oracle.sql.DATE")) {
        String metaDataClassName = rs.getMetaData().getColumnClassName(index);
        if ("java.sql.Timestamp".equals(metaDataClassName)
                || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) {
            obj = rs.getTimestamp(index);
        } else {
            obj = rs.getDate(index);
        }
    } else if (obj != null && obj instanceof Date) {
        if ("java.sql.Timestamp".equals(rs.getMetaData().getColumnClassName(index))) {
            obj = rs.getTimestamp(index);
        }
    }
    return obj;
}