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.nabla.wapp.server.json.SqlColumn.java

public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException {
    switch (type) {
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.SMALLINT:
    case Types.TINYINT:
        record.put(label, rs.getInt(column));
        break;/*from   w w  w . j av  a 2s  .com*/
    case Types.BOOLEAN:
    case Types.BIT:
        record.put(label, rs.getBoolean(column));
        break;
    case Types.DATE:
        final Date dt = rs.getDate(column);
        if (rs.wasNull())
            record.put(label, null);
        else
            record.put(label, new JSonDate(dt));
        return;
    case Types.TIMESTAMP:
        final Timestamp tm = rs.getTimestamp(column);
        if (rs.wasNull())
            record.put(label, null);
        else
            record.put(label, timeStampFormat.format(tm));
        return;
    case Types.DOUBLE:
        record.put(label, rs.getDouble(column));
        break;
    case Types.FLOAT:
        record.put(label, rs.getFloat(column));
        break;
    case Types.NULL:
        record.put(label, null);
        return;
    default:
        record.put(label, rs.getString(column));
        break;
    }
    if (rs.wasNull())
        record.put(label, null);
}

From source file:io.github.sislivros.persistencia.UsuarioBdDao.java

public Usuario preencherObjeto(ResultSet rs) {
    Usuario usuario = new Usuario();
    try {/*  w ww . j a  v a2  s .  com*/
        usuario.setApelido(rs.getString("apelido"));
        usuario.setDataNascimento(rs.getDate("data_nascimento"));
        usuario.setCidade(rs.getString("cidade"));
        usuario.setEstado(rs.getString("estado"));
        usuario.setEmail(rs.getString("email"));
        usuario.setFotoPerfil(rs.getString("foto_perfil"));
        usuario.setFotoCapa(rs.getString("foto_capa"));
        usuario.setNome(rs.getString("nome"));
        usuario.setSenha(rs.getString("senha"));
        usuario.setId(rs.getInt("id"));
        usuario.setDataCadastro(rs.getTimestamp("data_cadastro"));

        for (TipoUsuario t : TipoUsuario.values()) {
            if (t.id == rs.getInt("tipo")) {
                usuario.setTipo(t);
                break;
            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    }

    return usuario;
}

From source file:com.havoc.hotel.admin.dao.impl.BookingDAOImpl.java

private Booking mapData(ResultSet rs) throws SQLException {
    Booking b = new Booking();
    b.setBookingId(rs.getInt("booking_id"));
    b.setFirstName(rs.getString("first_name"));
    b.setLastName(rs.getString("last_name"));
    Room r = new Room();
    r.setRoomId(rs.getInt("room_id"));
    r.setRoomPrice(rs.getInt("room_price"));
    r.setRoomNumber(rs.getInt("room_number"));
    b.setRoom(r);//from   w  w w  .j a va 2  s .c  om
    b.setCheckinDate(rs.getDate("checkin_date"));
    b.setTotalDays(rs.getInt("total_days"));
    b.setTotalNights(rs.getInt("total_nights"));
    b.setCheckoutDate(rs.getDate("checkout_date"));
    Customer c = new Customer();
    c.setCustomerId(rs.getInt("customer_id"));
    b.setCustomer(c);
    b.setTotalPrice(rs.getInt("total_price"));
    b.setPdf(rs.getString("pdf"));
    b.setStatus(rs.getBoolean("status"));

    return b;

}

From source file:com.carfinance.module.vehiclemanage.domain.VehicleInfoRowMapper.java

public VehicleInfo mapRow(ResultSet rs, int arg1) throws SQLException {
    VehicleInfo vehicleInfo = new VehicleInfo();

    vehicleInfo.setId(rs.getLong("id"));
    vehicleInfo.setBrand(rs.getString("brand"));
    vehicleInfo.setModel(rs.getString("model"));
    vehicleInfo.setColor(rs.getString("color"));
    vehicleInfo.setCarframe_no(rs.getString("carframe_no"));
    vehicleInfo.setEngine_no(rs.getString("engine_no"));
    vehicleInfo.setBuy_at(rs.getDate("buy_at"));
    vehicleInfo.setSupplier(rs.getString("supplier"));
    vehicleInfo.setLicense_plate(rs.getString("license_plate"));
    vehicleInfo.setCard_at(rs.getDate("card_at"));
    vehicleInfo.setLimited_at(rs.getDate("limited_at"));
    vehicleInfo.setGuide_price(rs.getDouble("guide_price"));
    vehicleInfo.setVehicle_price(rs.getDouble("vehicle_price"));
    vehicleInfo.setVehicle_tax(rs.getDouble("vehicle_tax"));
    vehicleInfo.setInsurance_company(rs.getString("insurance_company"));
    vehicleInfo.setStrong_insurance(rs.getDouble("strong_insurance"));
    vehicleInfo.setStrong_insurance_expire_at(rs.getDate("strong_insurance_expire_at"));
    vehicleInfo.setVehicle_vessel_tax(rs.getDouble("vehicle_vessel_tax"));
    vehicleInfo.setBusiness_insurance(rs.getDouble("business_insurance"));
    vehicleInfo.setBusiness_insurance_expire_at(rs.getDate("business_insurance_expire_at"));
    vehicleInfo.setKm(rs.getLong("km"));
    vehicleInfo.setMaintian_on_km(rs.getLong("maintian_on_km"));
    vehicleInfo.setGps(rs.getString("gps"));
    vehicleInfo.setCurrent_city(rs.getLong("current_city"));
    vehicleInfo.setCurrent_shop(rs.getLong("current_shop"));
    vehicleInfo.setLease_status(rs.getString("lease_status"));
    vehicleInfo.setPeccancy_status(rs.getString("peccancy_status"));
    vehicleInfo.setArchive_no(rs.getString("archive_no"));
    vehicleInfo.setInventory_no(rs.getString("inventory_no"));
    vehicleInfo.setRegistry_certificate(rs.getString("registry_certificate"));
    vehicleInfo.setCertificate_direction(rs.getString("certificate_direction"));
    vehicleInfo.setLoan_bank(rs.getString("loan_bank"));
    vehicleInfo.setConsistency_cer(rs.getString("consistency_cer"));
    vehicleInfo.setCheck_list(rs.getString("check_list"));
    vehicleInfo.setDuty_paid_proof(rs.getString("duty_paid_proof"));
    vehicleInfo.setRecord(rs.getString("record"));
    vehicleInfo.setRemark(rs.getString("remark"));
    vehicleInfo.setCreate_by(rs.getLong("create_by"));
    vehicleInfo.setCreate_at(rs.getDate("create_at"));
    vehicleInfo.setCreate_by(rs.getLong("update_by"));
    vehicleInfo.setCreate_at(rs.getDate("update_at"));
    vehicleInfo.setOriginal_org(rs.getLong("original_org"));
    vehicleInfo.setNext_main_km(rs.getLong("next_main_km"));

    try {//from w w w  .jav  a2  s.c om
        vehicleInfo.setFinancing_rent_company(rs.getString("financing_rent_company"));
    } catch (Exception e) {
    }
    try {
        vehicleInfo.setFinancing_rent_price(rs.getDouble("financing_rent_price"));
    } catch (Exception e) {
    }
    try {
        vehicleInfo.setBail(rs.getDouble("bail"));
    } catch (Exception e) {
    }
    try {
        vehicleInfo.setMonthly_payment(rs.getDouble("monthly_payment"));
    } catch (Exception e) {
    }

    try {
        vehicleInfo.setEtc(rs.getString("etc"));
    } catch (Exception e) {
    }
    try {
        vehicleInfo.setEtc_money(rs.getDouble("etc_money"));
    } catch (Exception e) {
    }
    try {
        vehicleInfo.setOil_percent(rs.getInt("oil_percent"));
    } catch (Exception e) {
    }

    try {
        vehicleInfo.setDaily_price(rs.getDouble("daily_price"));
    } catch (Exception e) {
    }

    return vehicleInfo;
}

From source file:br.bookmark.db.util.ResultSetUtils.java

/**
 * Map JDBC objects to Java equivalents.
 * Used by getBean() and getBeans().//from   w w w.  ja va 2  s.c om
 * <p>
 * Some types not supported.
 * Many not work with all drivers.
 * <p>
 * Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER,
 * REAL, SMALLINT, TIME, TIMESTAMP, TINYINT.
 * Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY,
 * VARBINARY.
 * <p>
 * DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman.
 * Others not guaranteed.
 * @param classeDestino 
 * @throws NoSuchFieldException 
 * @throws SecurityException 
 */
private static void putEntry(Map properties, ResultSetMetaData metaData, ResultSet resultSet, int i,
        Class classeDestino) throws Exception {

    /*
    In a perfect universe, this would be enough
    properties.put(
        metaData.getColumnName(i),
        resultSet.getObject(i));
    But only String, Timestamp, and Integer seem to get through that way.
    */

    String columnName = metaData.getColumnName(i);

    // Testa se  uma FK
    /*Field[] fields = classeDestino.getDeclaredFields();
    for (int j = 0; j < fields.length; j++) {
    if (fields[j].getAnnotation(DBFK.class) != null) {
        properties.put(columnName, resultSet.getString(i));
    }
    }*/
    //System.out.println(i+"-"+metaData.getColumnType(i));
    switch (metaData.getColumnType(i)) {

    // http://java.sun.com/j2se/1.3.0/docs/api/java/sql/Types.html

    case Types.BIGINT:
        properties.put(columnName, new Long(resultSet.getLong(i)));
        break;

    case Types.DATE:
        properties.put(columnName, resultSet.getDate(i));
        break;

    case Types.DECIMAL:
    case Types.DOUBLE:
        properties.put(columnName, new Double(resultSet.getDouble(i)));
        break;

    case Types.FLOAT:
        properties.put(columnName, new Float(resultSet.getFloat(i)));
        break;

    case Types.INTEGER:
        int valor = 0;
        try { // Se o campo esta vazio d erro
            valor = resultSet.getInt(i);
        } catch (SQLException e) {
        }
        properties.put(columnName, new Integer(valor));
        break;

    case Types.REAL:
        properties.put(columnName, new Double(resultSet.getString(i)));
        break;

    case Types.SMALLINT:
        properties.put(columnName, new Short(resultSet.getShort(i)));
        break;

    case Types.TIME:
        properties.put(columnName, resultSet.getTime(i));
        break;

    case Types.TIMESTAMP:
        properties.put(columnName, resultSet.getTimestamp(i));
        break;

    // :FIXME: Throws java.lang.ClassCastException: java.lang.Integer
    // :FIXME: with Poolman and MySQL unless use getString.
    case Types.TINYINT:
        properties.put(columnName, new Byte(resultSet.getString(i)));
        break;

    case Types.CHAR:
    case Types.CLOB:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        // :FIXME: Handle binaries differently?
    case Types.BLOB:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
        properties.put(columnName, resultSet.getString(i));
        break;

    /*
        :FIXME: Add handlers for
        ARRAY
        BINARY
        BIT
        DISTINCT
        JAVA_OBJECT
        NULL
        NUMERIC
        OTHER
        REF
        STRUCT
    */

    // Otherwise, pass as *String property to be converted
    default:
        properties.put(columnName + "String", resultSet.getString(i));
        break;
    } // end switch

}

From source file:com.bleum.canton.jms.dao.impl.JMSTaskDao.java

@Override
public List<JMSTask> findTaskForProcessing(int type, int limit) {
    return this.jdbcTemplate.query(QUERY_TASK_FOR_PROCESSING, new Object[] { type, limit },
            new RowMapper<JMSTask>() {
                public JMSTask mapRow(ResultSet rs, int rowNum) throws SQLException {
                    JMSTask task = new JMSTask();
                    task.setId(rs.getLong("id"));
                    task.setContentId(rs.getString("content_id"));
                    task.setType(rs.getInt("type"));
                    task.setStatus(rs.getInt("status"));
                    task.setCreatedDate(rs.getDate("created_time"));
                    task.setOperatedDate(rs.getDate("operated_time"));
                    if (rs.getClob("message") != null) {
                        task.setMessage(CantonStringUtils.convertToString(rs.getClob("message")));
                    }/* ww  w  . j  a va2  s  . co  m*/
                    task.setRetry(rs.getInt("retry"));
                    task.setLastError(rs.getString("last_error"));
                    return task;
                }
            });
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java

@Override
public Purchase getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_purchase WHERE purchase_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Purchase>() {

        @Override//from ww w  .  j av a 2  s. com
        public Purchase mapRow(ResultSet rs, int i) throws SQLException {
            Purchase p = new Purchase();
            p.setId(rs.getInt("purchase_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setTotalCost(rs.getInt("total_cost"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setPurchaseDate(rs.getDate("purchase_date"));
            p.setPaymentMethod(rs.getString("payment_method"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java

@Override
public List<Purchase> getALL(boolean status) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_purchase WHERE 1=1";

    if (status) {
        sql += " AND status=1 ";
    }//from  w  w w. java 2  s.c om
    return jdbcTemplate.query(sql, new RowMapper<Purchase>() {

        @Override
        public Purchase mapRow(ResultSet rs, int i) throws SQLException {
            Purchase p = new Purchase();
            p.setId(rs.getInt("purchase_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setTotalCost(rs.getInt("total_cost"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setPurchaseDate(rs.getDate("purchase_date"));
            p.setPaymentMethod(rs.getString("payment_method"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Get the Statement column so that the results are mapped correctly.
 * (this has been copied from AbstractDatabaseAction and modified slightly)
 *//*  www . j av a  2s. co  m*/
public static Object getColumn(ResultSet set, Configuration column) throws Exception {

    Integer type = (Integer) JDBCTypeConversions.typeConstants.get(column.getAttribute("type"));
    String dbcol = column.getAttribute("name");
    Object value = null;

    switch (type.intValue()) {
    case Types.CLOB:
    case Types.CHAR:
        Clob dbClob = set.getClob(dbcol);
        int length = (int) dbClob.length();
        InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
        byte[] buffer = new byte[length];
        asciiStream.read(buffer);
        String str = new String(buffer);
        asciiStream.close();
        value = str;
        break;
    case Types.BIGINT:
        value = set.getBigDecimal(dbcol);
        break;
    case Types.TINYINT:
        value = new Byte(set.getByte(dbcol));
        break;
    case Types.VARCHAR:
        value = set.getString(dbcol);
        break;
    case Types.DATE:
        value = set.getDate(dbcol);
        break;
    case Types.DOUBLE:
        value = new Double(set.getDouble(dbcol));
        break;
    case Types.FLOAT:
        value = new Float(set.getFloat(dbcol));
        break;
    case Types.INTEGER:
        value = new Integer(set.getInt(dbcol));
        break;
    case Types.NUMERIC:
        value = new Long(set.getLong(dbcol));
        break;
    case Types.SMALLINT:
        value = new Short(set.getShort(dbcol));
        break;
    case Types.TIME:
        value = set.getTime(dbcol);
        break;
    case Types.TIMESTAMP:
        value = set.getTimestamp(dbcol);
        break;
    case Types.ARRAY:
        value = set.getArray(dbcol); // new Integer(set.getInt(dbcol));
        break;
    case Types.BIT:
        value = BooleanUtils.toBooleanObject(set.getBoolean(dbcol));
        break;
    case Types.STRUCT:
        value = (Struct) set.getObject(dbcol);
        break;
    case Types.OTHER:
        value = set.getObject(dbcol);
        break;

    default:
        // The blob types have to be requested separately, via a Reader.
        value = "";
        break;
    }

    return value;
}

From source file:com.fpmislata.banco.persistencia.impl.MovimientoBancarioDAOImplJDBC.java

@Override
public List<MovimientoBancario> findAll() {
    List<MovimientoBancario> movimientosBancarios = new ArrayList<>();
    Connection connection = connectionFactory.getConnection();
    String SQL = "SELECT * FROM movimientobancario ";

    try {/*  w  ww  .  j  a v a 2s.  co m*/
        PreparedStatement preparedStatement = connection.prepareStatement(SQL);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            MovimientoBancario movimientoBancario = new MovimientoBancario();
            movimientoBancario.setId(resultSet.getInt("id"));
            movimientoBancario.setCuentaPertenece(resultSet.getInt("cuentapertenece"));
            movimientoBancario.setImporte(resultSet.getString("importe"));
            movimientoBancario.setFecha(resultSet.getDate("fecha"));
            movimientoBancario.setSaldoTotal(resultSet.getString("saldototal"));
            movimientoBancario.setTipoMovimiento(resultSet.getString("tipomovimiento"));
            movimientoBancario.setConcepto(resultSet.getString("concepto"));
            movimientosBancarios.add(movimientoBancario);
        }

        return movimientosBancarios;
    } catch (Exception ex) {
        throw new RuntimeException("Error al hacer la consulta", ex);
    } finally {
        try {
            connection.close();
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    }
}