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:gov.nih.nci.ncicb.tcga.dcc.common.dao.UUIDDAOImpl.java
private ParameterizedRowMapper<Barcode> getBarcodeRowMapper() { return new ParameterizedRowMapper<Barcode>() { public Barcode mapRow(final ResultSet resultSet, final int rowNum) throws SQLException { final Barcode barcode = new Barcode(); barcode.setBarcode(resultSet.getString("BARCODE")); barcode.setBarcodeId(resultSet.getLong("BARCODE_ID")); barcode.setDisease(getDisease(resultSet.getInt("DISEASE_ID"))); barcode.setEffectiveDate(resultSet.getDate("EFFECTIVE_DATE")); barcode.setUuid(resultSet.getString("UUID")); barcode.setItemTypeId(resultSet.getLong("ITEM_TYPE_ID")); return barcode; }// w w w. ja va 2 s . c o m }; }
From source file:com.sfs.whichdoctor.analysis.AgedDebtorsAnalysisDAOImpl.java
/** * Load receipt map, where integer = guid of person/organisation. * * @param analysis the analysis//from ww w. jav a2 s . com * @return the hash map of receipts */ @SuppressWarnings("unchecked") private HashMap<Integer, ReceiptBean> loadLastReceipts(final AgedDebtorsAnalysisBean analysis) { HashMap<Integer, ReceiptBean> lastReceipts = new HashMap<Integer, ReceiptBean>(); StringBuffer sql = new StringBuffer(); sql.append(this.getSQL().getValue("agedDebtors/lastReceipts")); sql.append(" WHERE "); sql.append(buildSqlWhere(analysis, "fs1.PersonId", "fs1.OrganisationId", false)); sql.append(" GROUP BY fs1.PersonId"); if (dataLogger.isDebugEnabled()) { dataLogger.debug("SQL: " + sql.toString()); } Collection<ReceiptBean> receipts = new ArrayList<ReceiptBean>(); try { receipts = this.getJdbcTemplateReader().query(sql.toString(), new Object[] {}, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { ReceiptBean receipt = new ReceiptBean(); receipt.setGUID(rs.getInt("Id")); receipt.setAbbreviation(rs.getString("Abbreviation")); receipt.setNumber(rs.getString("Number")); receipt.setPersonId(rs.getInt("PersonId")); receipt.setOrganisationId(rs.getInt("OrganisationId")); receipt.setNetValue(rs.getDouble("NetValue")); try { receipt.setIssued(rs.getDate("Issued")); } catch (SQLException sqe) { dataLogger.error("Error loading issued date: " + sqe.getMessage()); } return receipt; } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search dataLogger.debug("No results found for this search: " + ie.getMessage()); } for (ReceiptBean receipt : receipts) { if (receipt.getPersonId() > 0) { lastReceipts.put(receipt.getPersonId(), receipt); } if (receipt.getOrganisationId() > 0) { lastReceipts.put(receipt.getOrganisationId(), receipt); } } return lastReceipts; }
From source file:com.adito.jdbc.JDBCUserDatabase.java
public Iterable<User> allUsers() throws UserDatabaseException { try {/* ww w . j a va 2s. c o m*/ // Get the allowed roles from the database JDBCPreparedStatement ps = db.getStatement("select.users"); try { ResultSet results = ps.executeQuery(); try { Vector<User> tmp = new Vector<User>(); while (results.next()) { String username = results.getString("username"); Realm usersRealm = UserDatabaseManager.getInstance().getRealm(results.getInt("realm_ID")); if (usersRealm.equals(realm)) { DefaultUser u = new DefaultUser(results.getString("username"), results.getString("email"), results.getString("fullname"), results.getDate("last_password_change"), usersRealm); addRoles(u); tmp.add(u); } } return tmp; } finally { results.close(); } } finally { ps.releasePreparedStatement(); } } catch (Exception e) { throw new UserDatabaseException("failed to get all users", e); } }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.MoteTestbedAssignmentSqlAdapter.java
public Map<Integer, MoteTestbedAssignment> readMoteTestbedAssignments() throws AdaptationException { Map<Integer, MoteTestbedAssignment> tbAssignments = new HashMap<Integer, MoteTestbedAssignment>(); Connection connection = null; Statement statement = null;//from www. j ava2 s . co m ResultSet resultSet = null; try { String query = "SELECT * FROM MoteTestbedAssignments"; connection = DriverManager.getConnection(CONN_STR); statement = connection.createStatement(); resultSet = statement.executeQuery(query); while (resultSet.next()) { int id; int testbedID; int moteID; int moteAddress; int moteLocationX; int moteLocationY; Date timestamp; id = resultSet.getInt(Index.ID.index()); testbedID = resultSet.getInt(Index.TESTBEDID.index()); moteID = resultSet.getInt(Index.MOTEID.index()); moteAddress = resultSet.getInt(Index.MOTEADDRESS.index()); moteLocationX = resultSet.getInt(Index.MOTELOCATIONX.index()); moteLocationY = resultSet.getInt(Index.MOTELOCATIONY.index()); timestamp = resultSet.getDate(Index.TIMESTAMP.index()); MoteTestbedAssignment mta = new MoteTestbedAssignment(id, testbedID, moteID, moteAddress, moteLocationX, moteLocationY, timestamp); tbAssignments.put(id, mta); } } catch (SQLException ex) { String msg = "SQLException in readMoteTestbedAssignments"; 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 tbAssignments; }
From source file:br.gov.jfrj.siga.gc.gsa.GcInformacaoAdaptor.java
/** Gives the bytes of a document referenced with id. */ public void getDocContent(Request req, Response resp) throws IOException { DocId id = req.getDocId();// w ww. ja v a2 s .c om log.fine("obtendo id = " + id); long primaryKey; try { primaryKey = Long.parseLong(id.getUniqueId()); } catch (NumberFormatException nfe) { resp.respondNotFound(); return; } Connection conn = null; PreparedStatement stmt = null; String query = "select ACRONIMO_ORGAO_USU, ANO, NUMERO, NOME_TIPO_INFORMACAO, TITULO, NOME_ACESSO, HIS_DT_INI, CONTEUDO_TIPO, CONTEUDO, " + "(select nome_pessoa from corporativo.dp_pessoa pes where pes.id_pessoa = inf.id_pessoa_titular) SUBSCRITOR, " + "(select sigla_lotacao from corporativo.dp_lotacao lot where lot.id_lotacao = inf.id_lotacao_titular) SUBSCRITOR_LOTACAO, " + "(select nome_pessoa from corporativo.dp_pessoa pes, corporativo.cp_identidade idn where idn.id_pessoa = pes.id_pessoa and idn.id_identidade = inf.his_idc_ini) CADASTRANTE, " + "(select sigla_lotacao from corporativo.dp_lotacao lot, corporativo.dp_pessoa pes, corporativo.cp_identidade idn where lot.id_lotacao = pes.id_lotacao and idn.id_pessoa = pes.id_pessoa and idn.id_identidade = inf.his_idc_ini) CADASTRANTE_LOTACAO " + "from sigagc.gc_informacao inf, sigagc.gc_arquivo arq, corporativo.cp_orgao_usuario ou, sigagc.gc_tipo_informacao tp, sigagc.gc_acesso ac " + "where inf.id_arquivo = arq.id_conteudo and inf.id_orgao_usuario = ou.id_orgao_usu and inf.id_tipo_informacao = tp.id_tipo_informacao and inf.id_acesso = ac.id_acesso and numero is not null and ac.id_acesso = 1 " + "and inf.id_informacao = ?"; try { conn = getConnection(); stmt = conn.prepareStatement(query); stmt.setLong(1, primaryKey); ResultSet rs = stmt.executeQuery(); if (!rs.next()) { resp.respondNotFound(); return; } // Add Metadata // addMetadata(resp, "orgao", rs.getString("ACRONIMO_ORGAO_USU")); String codigo = rs.getString("ACRONIMO_ORGAO_USU") + "-GC-" + rs.getInt("ANO") + "/" + Long.toString(rs.getLong("NUMERO") + 100000).substring(1); addMetadata(resp, "codigo", codigo); addMetadata(resp, "origem", "Conhecimento"); addMetadata(resp, "especie", rs.getString("NOME_TIPO_INFORMACAO")); addMetadata(resp, "descricao", rs.getString("TITULO")); addMetadata(resp, "acesso", rs.getString("NOME_ACESSO")); addMetadata(resp, "data", getDtYYYYMMDD(rs.getDate("HIS_DT_INI"))); addMetadata(resp, "subscritor_lotacao", rs.getString("SUBSCRITOR_LOTACAO")); addMetadata(resp, "subscritor", rs.getString("SUBSCRITOR")); addMetadata(resp, "cadastrante_lotacao", rs.getString("CADASTRANTE_LOTACAO")); addMetadata(resp, "cadastrante", rs.getString("CADASTRANTE")); // Add Acl // // List<GroupPrincipal> groups = new ArrayList<>(); // groups.add(new GroupPrincipal(s)); // Acl acl = new Acl.Builder().setPermitGroups(groups) // .setEverythingCaseInsensitive().build(); // resp.setAcl(acl); // Add Atributos essenciais // resp.setCrawlOnce(false); resp.setLastModified(rs.getDate("HIS_DT_INI")); try { String numero = Long.toString(rs.getLong("NUMERO") + 100000).substring(1); resp.setDisplayUrl( new URI(permalink + rs.getString("ACRONIMO_ORGAO_USU") + "GC" + rs.getInt("ANO") + numero)); } catch (URISyntaxException e) { throw new RuntimeException(e); } // Add Conteudo // if ("text/html".equals(rs.getString("CONTEUDO_TIPO"))) { String html = new String(rs.getBytes("CONTEUDO"), "UTF-8"); if (html != null) { resp.setContentType("text/html"); resp.getOutputStream().write(html.getBytes()); return; } } else { resp.respondNotFound(); return; } } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.glaf.base.modules.todo.business.TodoJobBean.java
public List getTasks() { List todos = todoService.getSQLTodos(); List rows = new java.util.ArrayList(); if (todos != null && todos.size() > 0) { Iterator iterator = todos.iterator(); while (iterator.hasNext()) { Todo todo = (Todo) iterator.next(); if (StringUtils.isNotEmpty(todo.getSql())) { logger.info(todo.getId() + ":" + todo.getSql()); Map rowsMap = new java.util.HashMap(); java.sql.Connection conn = null; java.sql.PreparedStatement psmt = null; java.sql.ResultSet rs = null; try { 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 (Long.valueOf(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; }//from ww w. ja v a2 s . c o m } rowsMap.put(model.getRowId(), model); } rs.close(); psmt.close(); rs = null; psmt = null; } catch (java.sql.SQLException ex) { logger.debug(todo.getId() + ":" + todo.getSql()); ex.printStackTrace(); } finally { JdbcUtils.close(rs); JdbcUtils.close(psmt); JdbcUtils.close(conn); } if (rowsMap.size() > 0) { Iterator 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); } } } } } return rows; }
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Load receipt./* www. j a va 2 s .c o m*/ * * @param rs the rs * * @return the receipt bean */ private ReceiptBean loadReceipt(final ResultSet rs) { ReceiptBean receipt = null; try { receipt = new ReceiptBean(); // receipt not already loaded so enter details... receipt.setId(rs.getInt("ReceiptId")); receipt.setAbbreviation(rs.getString("ReceiptAbbreviation")); receipt.setNumber(rs.getString("ReceiptNo")); receipt.setBatchReference(rs.getInt("BatchReference")); receipt.setProcessAbbreviation(rs.getString("ReceiptProcessType")); receipt.setDescription(rs.getString("ReceiptDescription")); try { receipt.setIssued(rs.getDate("ReceiptIssued")); } catch (SQLException e) { receipt.setIssued(null); } receipt.setTypeName(rs.getString("ReceiptType")); receipt.setClassName(rs.getString("ReceiptClass")); // Add member/organisation if it exists.... if (rs.getInt("ReceiptPersonGUID") > 0) { receipt.setPerson(loadPerson(rs)); } if (rs.getInt("ReceiptOrganisationGUID") > 0) { receipt.setOrganisation(loadOrganisation(rs)); } } catch (SQLException sqe) { dataLogger.error("Error loading receipt details: " + sqe.getMessage()); } return receipt; }
From source file:com.twosigma.beaker.sql.QueryExecutor.java
private QueryResult executeQuery(int currentIterationIndex, BeakerParseResult queryLine, Connection conn, NamespaceClient namespaceClient) throws SQLException, ReadVariableException { QueryResult queryResult = new QueryResult(); try (PreparedStatement statement = conn.prepareStatement(queryLine.getResultQuery())) { this.statement = statement; int n = 1; for (BeakerInputVar parameter : queryLine.getInputVars()) { if (parameter.getErrorMessage() != null) throw new ReadVariableException(parameter.getErrorMessage()); Object obj;/*from w ww . j a v a 2 s . c o m*/ try { obj = namespaceClient.get(parameter.objectName); if (!parameter.isArray() && !parameter.isObject()) { statement.setObject(n, obj); } else if (!parameter.isArray() && parameter.isObject()) { statement.setObject(n, getValue(obj, parameter.getFieldName())); } else if (parameter.isArray()) { int index; if (currentIterationIndex > 0 && parameter.isAll()) { index = currentIterationIndex; } else { index = parameter.index; } if (!parameter.isObject()) { if (obj instanceof List) { statement.setObject(n, ((List) obj).get(index)); } else if (obj.getClass().isArray()) { Object arrayElement = Array.get(obj, index); statement.setObject(n, arrayElement); } } else { if (obj instanceof List) { statement.setObject(n, getValue(((List) obj).get(index), parameter.getFieldName())); } else if (obj.getClass().isArray()) { Object arrayElement = Array.get(obj, index); statement.setObject(n, getValue(arrayElement, parameter.getFieldName())); } } } n++; } catch (Exception e) { throw new ReadVariableException(parameter.objectName, e); } } boolean hasResultSet = statement.execute(); if (hasResultSet) { ResultSet rs = statement.getResultSet(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { queryResult.getColumns().add(rs.getMetaData().getColumnName(i)); queryResult.getTypes().add(rs.getMetaData().getColumnClassName(i)); } while (rs.next()) { if (rs.getMetaData().getColumnCount() != 0) { List<Object> row = new ArrayList<Object>(); queryResult.getValues().add(row); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { if (java.sql.Date.class.getName().equals(rs.getMetaData().getColumnClassName(i))) { java.sql.Date sqlDate = rs.getDate(i); row.add(sqlDate == null ? null : new Date(sqlDate.getTime())); } else { row.add(rs.getObject(i)); } } } } } } catch (SQLException e) { //Logger.getLogger(QueryExecutor.class.getName()).log(Level.SEVERE, null, e); try { conn.rollback(); } catch (Exception e1) { //Logger.getLogger(QueryExecutor.class.getName()).log(Level.SEVERE, null, e1); } throw e; } return queryResult; }
From source file:com.twosigma.beakerx.sql.QueryExecutor.java
private QueryResult executeQuery(int currentIterationIndex, BeakerParseResult queryLine, Connection conn, BeakerXClient namespaceClient) throws SQLException, ReadVariableException { QueryResult queryResult = new QueryResult(); try (PreparedStatement statement = conn.prepareStatement(queryLine.getResultQuery())) { this.statement = statement; int n = 1; for (BeakerInputVar parameter : queryLine.getInputVars()) { if (parameter.getErrorMessage() != null) throw new ReadVariableException(parameter.getErrorMessage()); Object obj;//from w w w . ja va2s . c o m try { obj = namespaceClient.get(parameter.objectName); if (!parameter.isArray() && !parameter.isObject()) { statement.setObject(n, obj); } else if (!parameter.isArray() && parameter.isObject()) { statement.setObject(n, getValue(obj, parameter.getFieldName())); } else if (parameter.isArray()) { int index; if (currentIterationIndex > 0 && parameter.isAll()) { index = currentIterationIndex; } else { index = parameter.index; } if (!parameter.isObject()) { if (obj instanceof List) { statement.setObject(n, ((List) obj).get(index)); } else if (obj.getClass().isArray()) { Object arrayElement = Array.get(obj, index); statement.setObject(n, arrayElement); } } else { if (obj instanceof List) { statement.setObject(n, getValue(((List) obj).get(index), parameter.getFieldName())); } else if (obj.getClass().isArray()) { Object arrayElement = Array.get(obj, index); statement.setObject(n, getValue(arrayElement, parameter.getFieldName())); } } } n++; } catch (Exception e) { throw new ReadVariableException(parameter.objectName, e); } } boolean hasResultSet = statement.execute(); if (hasResultSet) { ResultSet rs = statement.getResultSet(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { queryResult.getColumns().add(rs.getMetaData().getColumnName(i)); queryResult.getTypes().add(rs.getMetaData().getColumnClassName(i)); } while (rs.next()) { if (rs.getMetaData().getColumnCount() != 0) { List<Object> row = new ArrayList<Object>(); queryResult.getValues().add(row); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { if (java.sql.Date.class.getName().equals(rs.getMetaData().getColumnClassName(i))) { java.sql.Date sqlDate = rs.getDate(i); row.add(sqlDate == null ? null : new Date(sqlDate.getTime())); } else { row.add(rs.getObject(i)); } } } } } } catch (SQLException e) { //Logger.getLogger(QueryExecutor.class.getName()).log(Level.SEVERE, null, e); try { conn.rollback(); } catch (Exception e1) { //Logger.getLogger(QueryExecutor.class.getName()).log(Level.SEVERE, null, e1); } throw e; } return queryResult; }
From source file:com.sfs.whichdoctor.dao.ItemDAOImpl.java
/** * Load item.//from w ww . j a v a 2 s . c o m * * @param rs the rs * * @return the item bean * * @throws SQLException the SQL exception */ private ItemBean loadItem(final ResultSet rs) throws SQLException { ItemBean item = new ItemBean(); item.setId(rs.getInt("ItemId")); item.setGUID(rs.getInt("GUID")); item.setObject1GUID(rs.getInt("Object1GUID")); item.setObject2GUID(rs.getInt("Object2GUID")); item.setReferenceGUID(rs.getInt("ReferenceGUID")); item.setName(rs.getString("Name")); item.setTitle(rs.getString("Title")); item.setComment(rs.getString("Comment")); item.setItemType(rs.getString("ItemType")); item.setWeighting(rs.getInt("Weighting")); try { item.setStartDate(rs.getDate("StartDate")); } catch (SQLException sqe) { dataLogger.debug("Error parsing StartDate: " + sqe.getMessage()); } try { item.setEndDate(rs.getDate("EndDate")); } catch (SQLException sqe) { dataLogger.debug("Error parsing EndDate: " + sqe.getMessage()); } item.setPermission(rs.getString("Permission")); item.setActive(rs.getBoolean("Active")); item.setCreatedBy(rs.getString("CreatedBy")); try { item.setCreatedDate(rs.getDate("Created")); } catch (SQLException sqe) { dataLogger.debug("Error parsing CreatedDate: " + sqe.getMessage()); } if (StringUtils.equalsIgnoreCase(item.getItemType(), "Employment")) { // Order by employment date String start = ""; if (item.getStartDate() != null) { Long time = BASE_TIME - item.getStartDate().getTime(); start = String.valueOf(time); } item.setOrderIndex(start + rs.getString("OrderIndex"), rs.getRow()); } else { item.setOrderIndex(rs.getString("OrderIndex"), rs.getRow()); } return item; }