List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public Account getCustomerByUserId(String userId) throws DAOException { PreparedStatement getCustomerByUserId = null; try {/* w ww . ja va 2 s.c o m*/ getCustomerByUserId = sqlConnection.prepareStatement(SQL_SELECT_GET_CUSTOMER_BY_USERID); getCustomerByUserId.setString(1, userId); ResultSet rs = getCustomerByUserId.executeQuery(); if (rs.next()) { try { Account bean = new Account(rs.getInt(1), rs.getString(2), StockTraderUtility.convertToCalendar(rs.getDate(3)), rs.getBigDecimal(4), rs.getInt(5), rs.getBigDecimal(6), StockTraderUtility.convertToCalendar(rs.getDate(7)), rs.getInt(8), rs.getString(9)); return bean; } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } } } catch (SQLException e) { throw new DAOException("", e); } finally { if (getCustomerByUserId != null) { try { getCustomerByUserId.close(); } catch (SQLException e) { logger.debug("", e); } } } return null; }
From source file:com.sfs.whichdoctor.dao.ExamDAOImpl.java
/** * Load exam.//ww w .ja va 2 s . c o m * * @param rs the rs * @return the exam bean * @throws SQLException the sQL exception */ private ExamBean loadExam(final ResultSet rs) throws SQLException { ExamBean exam = new ExamBean(); exam.setId(rs.getInt("ExamId")); exam.setGUID(rs.getInt("GUID")); exam.setReferenceGUID(rs.getInt("ReferenceGUID")); exam.setType(rs.getString("Type")); exam.setTrainingOrganisation(rs.getString("TrainingOrganisation")); exam.setTrainingProgram(rs.getString("TrainingProgram")); exam.setStatus(rs.getString("Status")); exam.setStatusLevel(rs.getString("StatusLevel")); try { exam.setDateSat(rs.getDate("DateSat")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } exam.setLocation(rs.getString("Location")); exam.setAwardedMarks(rs.getInt("AwardedMarks")); exam.setTotalMarks(rs.getInt("TotalMarks")); exam.setActive(rs.getBoolean("Active")); try { exam.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } exam.setCreatedBy(rs.getString("CreatedBy")); try { exam.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } exam.setModifiedBy(rs.getString("ModifiedBy")); try { exam.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } exam.setExportedBy(rs.getString("ExportedBy")); return exam; }
From source file:org.apache.ode.bpel.extvar.jdbc.JdbcExternalVariableModule.java
RowVal execSelect(DbExternalVariable dbev, Locator locator) throws SQLException, ExternalVariableModuleException { RowKey rowkey = dbev.keyFromLocator(locator); if (__log.isDebugEnabled()) __log.debug("execSelect: " + rowkey); if (rowkey.missingDatabaseGeneratedValues()) { return null; }/* ww w.ja v a2 s . co m*/ if (rowkey.missingValues()) { throw new IncompleteKeyException(rowkey.getMissing()); } RowVal ret = dbev.new RowVal(); Connection conn = dbev.dataSource.getConnection(); PreparedStatement stmt = null; try { if (__log.isDebugEnabled()) __log.debug("Prepare statement: " + dbev.select); stmt = conn.prepareStatement(dbev.select); int idx = 1; for (Object k : rowkey) { if (__log.isDebugEnabled()) __log.debug("Set key parameter " + idx + ": " + k); stmt.setObject(idx++, k); } ResultSet rs = stmt.executeQuery(); try { if (rs.next()) { for (Column c : dbev._columns) { Object val; int i = c.idx + 1; if (c.isDate()) val = rs.getDate(i); else if (c.isTimeStamp()) val = rs.getTimestamp(i); else if (c.isTime()) val = rs.getTime(i); else if (c.isInteger()) val = new Long(rs.getLong(i)); else if (c.isReal()) val = new Double(rs.getDouble(i)); else if (c.isBoolean()) val = new Boolean(rs.getBoolean(i)); else val = rs.getObject(i); if (__log.isDebugEnabled()) __log.debug("Result column index " + c.idx + ": " + val); ret.set(c.idx, val); } } else return null; } finally { rs.close(); } } finally { if (stmt != null) stmt.close(); try { conn.close(); } catch (SQLException e) { // ignore } } return ret; }
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.jdbc.QuartzJobHistoryQueriesImpl.java
public QuartzJobHistoryQueriesImpl() { quartzJobHistoryRowMapper = new ParameterizedRowMapper<QuartzJobHistory>() { public QuartzJobHistory mapRow(final ResultSet resultSet, final int i) throws SQLException { final Long jobWSSubmissionDateAsLong = resultSet.getLong(QuartzJobHistory.JOB_WS_SUBMISSION_DATE); Date jobWSSubmissionDate = null; // if 0L is found, it means the job was not submitted through the web service (and converting that would give us The Epoch ...) if (jobWSSubmissionDateAsLong != 0L) { jobWSSubmissionDate = new Date(jobWSSubmissionDateAsLong); }/* ww w . j a v a 2 s. co m*/ final QuartzJobHistory quartzJobHistory = new QuartzJobHistory(resultSet.getString(JOB_NAME), resultSet.getString(JOB_GROUP), resultSet.getDate(FIRE_TIME), QuartzJobStatus.valueOf(resultSet.getString(STATUS)), resultSet.getDate(LAST_UPDATED), resultSet.getString(QuartzJobHistory.LINK_TEXT), Long.parseLong(resultSet.getString(QuartzJobHistory.ESTIMATED_UNCOMPRESSED_SIZE)), jobWSSubmissionDate); quartzJobHistory.setQueueName(resultSet.getString(QUEUE_NAME)); quartzJobHistory.setEnqueueDate(resultSet.getTimestamp(TIME_ENQUEUED)); return quartzJobHistory; } }; }
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Load debit./*w ww. j a v a 2 s .c o m*/ * * @param rs the rs * * @return the debit bean */ private DebitBean loadDebit(final ResultSet rs) { DebitBean debit = null; try { debit = new DebitBean(); debit.setGUID(rs.getInt("InvoiceGUID")); debit.setNumber(rs.getString("InvoiceNo")); debit.setAbbreviation(rs.getString("InvoiceAbbreviation")); debit.setDescription(rs.getString("InvoiceDescription")); try { debit.setIssued(rs.getDate("InvoiceIssued")); } catch (SQLException e) { debit.setIssued(null); } if (rs.getInt("InvoicePersonGUID") > 0) { // Member exists so load details PersonBean person = new PersonBean(); person.setGUID(rs.getInt("InvoicePersonGUID")); person.setPersonIdentifier(rs.getInt("InvoicePersonIdentifier")); person.setPreferredName(rs.getString("InvoicePreferredName")); person.setLastName(rs.getString("InvoiceLastName")); debit.setPerson(person); } if (rs.getInt("InvoiceOrganisationGUID") > 0) { // Organisation exists so load details OrganisationBean organisation = new OrganisationBean(); organisation.setGUID(rs.getInt("InvoiceOrganisationGUID")); organisation.setName(rs.getString("InvoiceOrganisation")); debit.setOrganisation(organisation); } debit.setValue(rs.getDouble("InvoiceValue")); debit.setNetValue(rs.getDouble("InvoiceNetValue")); debit.setGSTRate(rs.getDouble("InvoiceGSTRate")); debit.setCancelled(rs.getBoolean("InvoiceCancelled")); } catch (SQLException sqe) { dataLogger.error("Error loading debit details: " + sqe.getMessage()); } return debit; }
From source file:CSVWriter.java
private static String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; /* ww w . j a va 2s . 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:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public Holding getHoldingForUpdate(int orderId) throws DAOException { if (logger.isDebugEnabled()) { logger.debug("MySQLCustomerDAO.getHoldingForUpdate(int)\nOrder ID :" + orderId); }/*from w w w . j ava2s .com*/ Holding holding = null; PreparedStatement selectHoldingLockStat = null; try { selectHoldingLockStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING_LOCK); selectHoldingLockStat.setInt(1, orderId); ResultSet rs = selectHoldingLockStat.executeQuery(); if (rs.next()) { try { holding = new Holding(rs.getInt(1), rs.getInt(2), rs.getDouble(3), rs.getBigDecimal(4), StockTraderUtility.convertToCalendar(rs.getDate(5)), rs.getString(6)); return holding; } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } } } catch (SQLException e) { throw new DAOException("Exception is thrown when selecting the holding entry for order ID :" + orderId, e); } finally { if (selectHoldingLockStat != null) { try { selectHoldingLockStat.close(); } catch (SQLException e) { logger.debug("", e); } } } return holding; }
From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public Holding getHolding(String userId, int holdingID) throws DAOException { if (logger.isDebugEnabled()) { logger.debug("MSSQLCustomerDAO.getHolding(String,int)\nUserID :" + userId + "\nOrder ID :" + holdingID); }/* w w w . j a va 2s. co m*/ Holding holding = null; PreparedStatement selectHoldingNoLockStat = null; try { selectHoldingNoLockStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING_NOLOCK); selectHoldingNoLockStat.setInt(1, holdingID); selectHoldingNoLockStat.setString(2, userId); ResultSet rs = selectHoldingNoLockStat.executeQuery(); if (rs.next()) { try { holding = new Holding(rs.getInt(1), holdingID, rs.getDouble(2), rs.getBigDecimal(3), StockTraderUtility.convertToCalendar(rs.getDate(4)), rs.getString(5)); return holding; } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } } } catch (SQLException e) { logger.debug("", e); throw new DAOException("Exception is thrown when selecting the holding entry for userID :" + userId + " and orderID :" + holdingID, e); } finally { if (selectHoldingNoLockStat != null) { try { selectHoldingNoLockStat.close(); } catch (SQLException e) { logger.debug("", e); } } } return holding; }
From source file:com.xinferin.dao.DAOCustomerImpl.java
@Override public List<Customer> list() { String sql = "SELECT * FROM customer"; List<Customer> list = jdbcTemplate.query(sql, new RowMapper<Customer>() { @Override//from w ww. j ava2 s. co m public Customer mapRow(ResultSet rs, int rowNum) throws SQLException { Customer aCustomer = new Customer(); aCustomer.setId(rs.getInt("id")); aCustomer.setFname(rs.getString("fname")); aCustomer.setLname(rs.getString("lname")); aCustomer.setCompany(rs.getString("company")); aCustomer.setStreet(rs.getString("street")); aCustomer.setCity(rs.getString("city")); aCustomer.setState(rs.getString("state")); aCustomer.setCountry(rs.getString("country")); aCustomer.setPostcode(rs.getString("postcode")); aCustomer.setTelephone(rs.getString("telephone")); aCustomer.setEmail(rs.getString("email")); aCustomer.setComments(rs.getString("comments")); aCustomer.setDateAdded(rs.getDate("date_added")); return aCustomer; } }); return list; }
From source file:ui.Analyze.java
private Date tglMax() throws SQLException { Date tgl = null;/*from www . ja v a 2s . c om*/ java.sql.ResultSet r = d.keluar("select max(tgl)as intok from jual"); if (r.next()) tgl = r.getDate("intok"); r.close(); return tgl; }