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:ui.Analyze.java
private Date tglMin() throws SQLException { Date tgl = null;/*w w w . j a va2 s . c o m*/ java.sql.ResultSet r = d.keluar("select min(tgl)as intok from jual"); if (r.next()) tgl = r.getDate("intok"); r.close(); return tgl; }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
@SuppressWarnings("unchecked") private Session getSessionFromResultSet(ResultSet rs) throws SQLException { Session session = new Session(); session.setId(rs.getString(1));//from ww w . ja va2 s . c om session.setUser_id(rs.getInt(2)); session.setCreate_timestamp(rs.getDate(3)); InputStream is = rs.getBinaryStream(4); HashMap<String, Object> sessionMap = null; try { ObjectInputStream ois = new ObjectInputStream(is); sessionMap = (HashMap<String, Object>) ois.readObject(); } catch (Exception e) { sessionMap = new HashMap<String, Object>(); } session.setSessionMap(sessionMap); return session; }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.TestbedSqlAdapter.java
public Map<Integer, Testbed> readTestbeds() throws AdaptationException { Map<Integer, Testbed> testbeds = new HashMap<Integer, Testbed>(); Connection connection = null; Statement statement = null;//from www. j av a2s . c o m ResultSet resultSet = null; ProjectAdapter projectAdapter = AdapterFactory.createProjectAdapter(AdapterType.SQL); try { String query = "SELECT * FROM Testbeds"; connection = DriverManager.getConnection(CONN_STR); statement = connection.createStatement(); resultSet = statement.executeQuery(query); while (resultSet.next()) { int id; String name; String description; Blob imageBlob; Date timestamp; id = resultSet.getInt(Index.ID.index()); name = resultSet.getString(Index.NAME.index()); description = resultSet.getString(Index.DESCRIPTION.index()); imageBlob = resultSet.getBlob(Index.IMAGE.index()); timestamp = resultSet.getDate(Index.TIMESTAMP.index()); byte[] image = (imageBlob != null && imageBlob.length() > 0) ? imageBlob.getBytes(0, (int) imageBlob.length()) : null; Testbed testbed = new Testbed(id, name, description, image, timestamp); testbeds.put(id, testbed); } } catch (SQLException ex) { String msg = "SQLException in readTestbeds"; log.error(msg, ex); throw new AdaptationException(msg, ex); } finally { try { resultSet.close(); } catch (Exception ex) { } try { statement.close(); } catch (Exception ex) { } try { connection.close(); } catch (Exception ex) { } } return testbeds; }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Get one value into DbValue from ResultSet * // w ww. j av a2s . co m * @param rs * @param value * @throws WaarpDatabaseSqlException */ static public void getTrueValue(ResultSet rs, DbValue value) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: value.value = rs.getString(value.column); break; case Types.LONGVARCHAR: value.value = rs.getString(value.column); break; case Types.BIT: value.value = rs.getBoolean(value.column); break; case Types.TINYINT: value.value = rs.getByte(value.column); break; case Types.SMALLINT: value.value = rs.getShort(value.column); break; case Types.INTEGER: value.value = rs.getInt(value.column); break; case Types.BIGINT: value.value = rs.getLong(value.column); break; case Types.REAL: value.value = rs.getFloat(value.column); break; case Types.DOUBLE: value.value = rs.getDouble(value.column); break; case Types.VARBINARY: value.value = rs.getBytes(value.column); break; case Types.DATE: value.value = rs.getDate(value.column); break; case Types.TIMESTAMP: value.value = rs.getTimestamp(value.column); break; case Types.CLOB: value.value = rs.getClob(value.column).getCharacterStream(); break; case Types.BLOB: value.value = rs.getBlob(value.column).getBinaryStream(); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " for " + value.column); } } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Getting values in error: " + value.type + " for " + value.column, e); } }
From source file:com.apbc.dao.AgentPayablesDAO.java
public List<ExtractedAgentPaymentSummary> getPayablesTotalRow(PayPeriod pp, final KnownAgentDAO agent, final AgentLicenceDAO lic) { Date d1 = pp.getFromDate();// w w w . ja v a 2s.c o m Date d2 = pp.getToDate(); String datequeryPart = " where payment_date BETWEEN CAST('" + d1 + "'" + " AS DATE) and CAST('" + d2 + "' " + "AS DATE)"; String query = "select agent_id,transaction_type, creation_date," + "(select sum(agent_earned_commission) from asbckodbnew.agent_payables" + datequeryPart + " and transaction_type= " + 1 + " and agent_id = p1.agent_id" + " group by agent_id )as 'normal'," + "(select sum(agent_earned_commission) from asbckodbnew.agent_payables" + datequeryPart + " and transaction_type= " + 2 + " and agent_id = p1.agent_id group by agent_id )as 'chargeback'," + "(select sum(agent_earned_commission) from asbckodbnew.agent_payables" + datequeryPart + " and transaction_type= " + 3 + " and agent_id = p1.agent_id group by agent_id )as 'adjustments'," + " (select sum(agent_earned_commission) from asbckodbnew.agent_payables" + datequeryPart + " and agent_id = p1.agent_id group by agent_id) as 'allTotal'" + " from asbckodbnew.agent_payables p1 " + datequeryPart + "group by agent_id"; final Date d3 = pp.getUptoExtractDate(); final Integer payperiodid = Integer.valueOf(pp.getPayperiodId()); return template.query(query, new RowMapper<ExtractedAgentPaymentSummary>() { @Override public ExtractedAgentPaymentSummary mapRow(ResultSet rs, int rownumber) throws SQLException { ExtractedAgentPaymentSummary e = new ExtractedAgentPaymentSummary(); e.setAgent_id(rs.getInt("agent_id")); e.setPayadjustments(rs.getLong("adjustments")); e.setPaynormal(rs.getLong("normal")); e.setPaychargeback(rs.getLong("chargeback")); e.setPaymenttotal(rs.getLong("allTotal")); e.setPayperiod(payperiodid); e.setAgent_name(getAgentName(agent, rs.getInt("agent_id"))); // AGENT NAME TO QUERY FROM AGENT TABLE...BY USING AGENT_ID e.setPayperiodupto(d3); e.setCreationdate(rs.getDate("creation_date")); return e; } }); }
From source file:com.netspective.sparx.form.DialogContextUtils.java
public void populateFieldValuesFromResultSet(DialogContext dc, ResultSet rs) throws SQLException { if (rs.next()) { ResultSetMetaData rsmd = rs.getMetaData(); int colsCount = rsmd.getColumnCount(); DialogFieldStates fieldStates = dc.getFieldStates(); for (int i = 1; i <= colsCount; i++) { String fieldName = rsmd.getColumnName(i).toLowerCase(); DialogField.State state = fieldStates.getState(fieldName, null); if (state != null) { // for columns that are Date objects, use the object setter instead of the text setter // because we don't need to do unnecessary formatting/parsing if (rsmd.getColumnType(i) == Types.DATE) state.getValue().setValue(rs.getDate(i)); else state.getValue().setTextValue(rs.getString(i)); }/*from ww w . ja v a2 s. c o m*/ } } }
From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public List<Order> getOrders(String userId, boolean top, int maxTop, int maxDefault) throws DAOException { PreparedStatement selectOrdersById = null; try {/*from ww w. j av a 2 s . c om*/ String sqlQuery; if (top) { sqlQuery = "SELECT " + SQL_SELECT_ORDERS_BY_ID + " FETCH FIRST " + maxTop + " ROWS ONLY"; } else { sqlQuery = "SELECT " + SQL_SELECT_ORDERS_BY_ID + " FETCH FIRST " + maxDefault + " ROWS ONLY"; } selectOrdersById = sqlConnection.prepareStatement(sqlQuery); selectOrdersById.setString(1, userId); ResultSet rs = selectOrdersById.executeQuery(); List<Order> orders = new ArrayList<Order>(); try { while (rs.next()) { int orderId = rs.getInt(1); Calendar openDate = StockTraderUtility.convertToCalendar(rs.getDate(4)); Calendar completionDate = null; try { if (rs.getDate(5) != null) { completionDate = StockTraderUtility.convertToCalendar(rs.getDate(5)); } else { completionDate = Calendar.getInstance(); completionDate.setTimeInMillis(0); } } catch (SQLException e) { logger.debug("", e); completionDate = Calendar.getInstance(); completionDate.setTimeInMillis(0); } Order orderBean = new Order(orderId, rs.getString(2), rs.getString(3), openDate, completionDate, rs.getDouble(6), rs.getBigDecimal(7), rs.getBigDecimal(8), rs.getString(9)); orders.add(orderBean); } } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } return orders; } catch (SQLException e) { throw new DAOException("", e); } finally { if (selectOrdersById != null) { try { selectOrdersById.close(); } catch (SQLException e) { logger.debug("", e); } } } }
From source file:com.moss.schematrax.SchemaUpdater.java
private List listAppliedUpdates(Connection jdbcConnection, String schemaName) throws SQLException { List<AppliedSchemaUpdate> appliedUpdates = new ArrayList<AppliedSchemaUpdate>(); ResultSet updates = jdbcConnection.createStatement() .executeQuery("SELECT id, dateApplied FROM " + schemaName + ".SCHEMA_UPDATES"); while (updates.next()) { AppliedSchemaUpdate update = new AppliedSchemaUpdate(); update.setId(updates.getString("id")); update.setDateApplied(updates.getDate("dateApplied")); appliedUpdates.add(update);//from w ww . j a va 2 s. co m } return appliedUpdates; }
From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public List<Order> getCompletedOrders(String userId) throws DAOException { PreparedStatement selectClosedOrders = null; PreparedStatement updateClosedOrders = null; try {// w w w . j a v a 2s.com selectClosedOrders = sqlConnection.prepareStatement(SQL_SELECT_COMPLETED_ORDERS); selectClosedOrders.setString(1, userId); ResultSet rs = selectClosedOrders.executeQuery(); List<Order> closedOrders = new ArrayList<Order>(); try { while (rs.next()) { int orderId = rs.getInt(1); Calendar openDate = StockTraderUtility.convertToCalendar(rs.getDate(4)); Calendar completionDate = null; try { completionDate = StockTraderUtility.convertToCalendar(rs.getDate(5)); } catch (SQLException e) { logger.debug("", e); completionDate = Calendar.getInstance(); completionDate.setTimeInMillis(0); } Order closedOrderBean = new Order(orderId, rs.getString(2), rs.getString(3), openDate, completionDate, rs.getDouble(6), rs.getBigDecimal(7), rs.getBigDecimal(8), rs.getString(9)); closedOrderBean.setOrderStatus(StockTraderUtility.ORDER_STATUS_CLOSED); closedOrders.add(closedOrderBean); } } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } if (!closedOrders.isEmpty()) { updateClosedOrders = sqlConnection.prepareStatement(SQL_UPDATE_CLOSED_ORDERS); updateClosedOrders.setString(1, userId); updateClosedOrders.executeUpdate(); } return closedOrders; } catch (SQLException e) { throw new DAOException("", e); } finally { if (selectClosedOrders != null) { try { selectClosedOrders.close(); } catch (SQLException e) { logger.debug("", e); } } if (updateClosedOrders != null) { try { selectClosedOrders.close(); } catch (SQLException e) { logger.debug("", e); } } } }
From source file:com.glaf.base.modules.todo.business.TodoJobBean.java
public void createTodoInstances(long todoId) { Todo todo = todoService.getTodo(todoId); Map<String, TodoInstance> rowsMap = new java.util.HashMap<String, TodoInstance>(); java.sql.Connection conn = null; java.sql.PreparedStatement psmt = null; java.sql.ResultSet rs = null; try {/*from w ww. ja va2 s . c o m*/ conn = DBConnectionFactory.getConnection(); psmt = conn.prepareStatement(todo.getSql()); rs = psmt.executeQuery(); java.sql.ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { TodoInstance model = new TodoInstance(); model.setRowId(rs.getString(1)); model.setStartDate(rs.getDate(2)); if (rsmd.getColumnCount() == 3) { switch (new Long(todo.getId()).intValue()) { case 8005: case 7001: case 7002: case 7003: case 7004: case 17001: case 17010: case 18001: case 19001: case 20001: case 20084001: model.setDeptId(rs.getLong(3)); break; default: model.setActorId(rs.getString(3)); break; } } rowsMap.put(model.getRowId(), model); } rs.close(); psmt.close(); rs = null; psmt = null; } catch (java.sql.SQLException ex) { ex.printStackTrace(); } finally { JdbcUtils.close(rs); JdbcUtils.close(psmt); JdbcUtils.close(conn); } List<TodoInstance> rows = new java.util.ArrayList<TodoInstance>(); if (rowsMap.size() > 0) { Iterator<String> iter = rowsMap.keySet().iterator(); while (iter.hasNext()) { String rowId = (String) iter.next(); TodoInstance model = (TodoInstance) rowsMap.get(rowId); Date startDate = model.getStartDate(); if (startDate == null) { startDate = new java.util.Date(); } model.setProvider("sql"); model.setLinkType(todo.getLinkType()); model.setAppId(todo.getAppId()); model.setModuleId(todo.getModuleId()); model.setTodoId(todo.getId()); model.setRoleId(todo.getRoleId()); model.setRoleCode(todo.getRoleCode()); model.setTitle(todo.getTitle()); model.setCreateDate(new Date(System.currentTimeMillis())); model.setStartDate(startDate); int limitDay = todo.getLimitDay(); int ahour = todo.getXa(); int bhour = todo.getXb(); Date limitWorkDate = workCalendarService.getWorkDate(startDate, limitDay); long time = limitWorkDate.getTime(); Date cautionDate = new Date(time - ahour * DateUtils.HOUR); Date pastDueDate = new Date(time + bhour * DateUtils.HOUR); model.setAlarmDate(cautionDate); model.setPastDueDate(pastDueDate); model.setRowId(rowId); model.setVersionNo(System.currentTimeMillis()); rows.add(model); } } todoService.createTodoInstances(todoId, rows); }