Example usage for java.sql ResultSet getDate

List of usage examples for java.sql ResultSet getDate

Introduction

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

Prototype

java.sql.Date getDate(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.Date object in the Java programming language.

Usage

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static List<Object[]> transformToList(ResultSet rs) throws SQLException {
    ResultSetMetaData rsMetaData = rs.getMetaData();

    int numberOfColumns = rsMetaData.getColumnCount();

    List<Object[]> result = new ArrayList<>(numberOfColumns);

    while (rs.next()) {
        Object[] row = new Object[numberOfColumns];
        for (int i = 0; i < numberOfColumns; i++) {
            if (rsMetaData.getColumnType(i + 1) == Types.TIMESTAMP) {
                row[i] = rs.getDate(i + 1);
            } else {
                row[i] = rs.getObject(i + 1);
            }//  ww w  .  j a v  a  2s. c  o  m
        }
        result.add(row);
    }

    return result;
}

From source file:database.ExerciseDAOImpl.java

public List<List> listRecentExercises() {

    // get all exercise dates
    String SQL1 = "SELECT DISTINCT date FROM exercise ORDER BY date DESC";
    List<Date> dates = template.query(SQL1, new RowMapper<Date>() {

        @Override//from  w  w  w.j  a va  2 s. c o  m
        public Date mapRow(ResultSet rs, int rowNum) throws SQLException {
            Date dates;
            dates = rs.getDate("date");
            return dates;
        }
    });

    List<ExerciseWithParticipants> ewpList = new ArrayList<>();
    List<List> listaa = new ArrayList<>();

    // get all users and hours from exercises
    for (int i = 0; i < dates.size(); i++) {
        Date date = dates.get(i);
        String SQL = "SELECT users.firstname, users.lastname, exercise.hours, exercise.date FROM exercise INNER JOIN users ON exercise.userid=users.id WHERE exercise.date = '"
                + date + "' ORDER BY firstname ASC";
        ewpList = template.query(SQL, new EWPMapper());
        listaa.add(ewpList);
    }

    return listaa;
}

From source file:info.gewton.slsecurity.dao.support.DefaultPostDao.java

@Override
public List<Post> retrieveByUser(final PostUser u) {
    return getJdbcTemplate().query(SQL_RETRIEVE_BY_USER, new String[] { u.getUsername() },
            new ParameterizedRowMapper<Post>() {
                public Post mapRow(ResultSet rs, int rowNum) throws SQLException {
                    Post p = new Post();
                    p.setId(rs.getInt(1));
                    p.setTimestamp(rs.getDate(2));
                    p.setText(rs.getString(3));
                    p.setUser(u);/*from   w ww .j a va  2 s .  co  m*/
                    return p;
                }
            });
}

From source file:com.healthcit.analytics.dao.rowmapper.UserRowMapper.java

@Override
public User mapRow(ResultSet rs, int index) throws SQLException {
    Long id = rs.getLong("id");
    String userName = rs.getString("username");
    String password = rs.getString("password");
    Date creationDate = rs.getDate("created_date");
    String email = rs.getString("email_addr");
    return new User(id, userName, password, email, creationDate);
}

From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java

/**
 * Creates a table cell from the value in the current row of the given result
 * set and the given column index. The type of the value is determined by the
 * given value type.//from ww w . java  2s.  c o  m
 *
 * @param rs The result set holding the data from the sql table. The result
 *     points to the current row.
 * @param valueType The value type of the column that the cell belongs to.
 * @param column The column index. Indexes are 0-based.
 *
 * @return The table cell.
 *
 * @throws SQLException Thrown when the connection to the database failed.
 */
private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException {
    Value value = null;

    // SQL indexes are 1- based.
    column = column + 1;

    switch (valueType) {
    case BOOLEAN:
        value = BooleanValue.getInstance(rs.getBoolean(column));
        break;
    case NUMBER:
        value = new NumberValue(rs.getDouble(column));
        break;
    case DATE:
        Date date = rs.getDate(column);
        // If date is null it is handled later.
        if (date != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month and date in the gregorian calendar.
            // Use the 'set' method with those parameters, and not the 'setTime'
            // method with the date parameter, since the Date object contains the
            // current time zone and it's impossible to change it to 'GMT'.
            gc.set(date.getYear() + 1900, date.getMonth(), date.getDate());
            value = new DateValue(gc);
        }
        break;
    case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
        if (timestamp != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month, date, hours, minutes and seconds in the
            // gregorian calendar. Use the 'set' method with those parameters,
            // and not the 'setTime' method with the timestamp parameter, since
            // the Timestamp object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(),
                    timestamp.getMinutes(), timestamp.getSeconds());
            // Set the milliseconds explicitly, as they are not saved in the
            // underlying date.
            gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000);
            value = new DateTimeValue(gc);
        }
        break;
    case TIMEOFDAY:
        Time time = rs.getTime(column);
        // If time is null it is handled later.
        if (time != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the hours, minutes and seconds of the time in the gregorian
            // calendar. Set the year, month and date to be January 1 1970 like
            // in the Time object.
            // Use the 'set' method with those parameters,
            // and not the 'setTime' method with the time parameter, since
            // the Time object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds());
            // Set the milliseconds explicitly, otherwise the milliseconds from
            // the time the gc was initialized are used.
            gc.set(GregorianCalendar.MILLISECOND, 0);
            value = new TimeOfDayValue(gc);
        }
        break;
    default:
        String colValue = rs.getString(column);
        if (colValue == null) {
            value = TextValue.getNullValue();
        } else {
            value = new TextValue(rs.getString(column));
        }
        break;
    }
    // Handle null values.
    if (rs.wasNull()) {
        return new TableCell(Value.getNullValueFromValueType(valueType));
    } else {
        return new TableCell(value);
    }
}

From source file:com.autentia.tnt.bill.migration.support.OriginalInformationRecoverer.java

/**
 * Recupera la fecha de pago o cobro de cada una de las facturas cuyo tipo se envia por parametro
 * @param billType tipo de factura// w  ww.java  2  s. c om
 */
public static Date[] getFechaFacturaOriginal(String billType) throws Exception {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    LineNumberReader file = null;
    Date[] result = new Date[0];

    try {
        log.info("RECOVERING FECHAS " + billType + " ORIGINALES");

        // connect to database
        Class.forName(BillToBillPaymentMigration.DATABASE_DRIVER);
        con = DriverManager.getConnection(BillToBillPaymentMigration.DATABASE_CONNECTION,
                BillToBillPaymentMigration.DATABASE_USER, BillToBillPaymentMigration.DATABASE_PASS); //NOSONAR
        con.setAutoCommit(false); // DATABASE_PASS vacia
        String sql = "SELECT date_add(creationDate, INTERVAL expiration DAY) as date FROM Bill B where billType = ? order by date";
        pstmt = con.prepareStatement(sql);
        pstmt.setString(1, billType);
        rs = pstmt.executeQuery();

        rs.last();
        result = new Date[rs.getRow()];
        rs.beforeFirst();
        int counter = 0;

        while (rs.next()) {
            result[counter] = rs.getDate(1);
            log.info("\t" + result[counter]);
            counter++;
        }
        con.commit();
    } catch (Exception e) {
        log.error("FAILED: WILL BE ROLLED BACK: ", e);
        if (con != null) {
            con.rollback();
        }
    } finally {
        cierraFichero(file);
        liberaConexion(con, pstmt, rs);
    }
    return result;
}

From source file:com.apress.prospringintegration.springenterprise.stocks.dao.jdbc.StockMapper.java

public Stock mapRow(ResultSet rs, int rowNum) throws SQLException {
    Stock stock = new Stock(rs.getString("SYMBOL"), rs.getString("INVENTORY_CODE"), rs.getString("EXCHANGE_ID"),
            rs.getFloat("PRICE_PER_SHARE"), rs.getInt("QUANTITY_AVAILABLE"), rs.getDate("PURCHASE_DATE"));

    stock.setId(rs.getInt("ID"));
    return stock;
}

From source file:org.smigo.comment.JdbcCommentDao.java

@Override
public List<Comment> getComments(String receiver) {
    return jdbcTemplate.query(SELECT, new Object[] { receiver }, new RowMapper<Comment>() {
        @Override// w  w w  . j a v a  2 s.  c  om
        public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new Comment(rs.getInt("ID"), rs.getString("TEXT"), rs.getString("SUBMITTER"),
                    rs.getInt("YEAR"), rs.getDate("CREATEDATE"), rs.getBoolean("UNREAD"));
        }
    });
}

From source file:net.freechoice.model.orm.Map_Account.java

public FC_Account mapRow(final ResultSet rs, int rowNum) throws SQLException {

    FC_Account account = new FC_Account();
    account.id = rs.getInt(1);//  w ww . jav  a  2 s  .com
    account.id_user_ = rs.getInt(2);
    account.date_create = rs.getDate(3);
    account.balance = rs.getBigDecimal(4);

    return account;
}

From source file:edu.hm.cs.goetz1.seminar.db.UserRowMapper.java

@Override
public User mapRow(ResultSet rs, int rowNum) throws SQLException {
    String email = rs.getString(1);
    String firstName = rs.getString(2);
    String lastName = rs.getString(3);
    String password = rs.getString(4);
    Date birthDate = rs.getDate(5);

    return new User(email, firstName, lastName, password, birthDate);
}