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:com.nec.harvest.service.impl.PurchaseServiceImlp.java
/** {@inheritDoc} */ @Override// ww w .j a va 2 s . c om public Map<String, PurchaseBean> findByOrgCodeAndMonth(String orgCode, String getSudo, String sql) throws ServiceException { if (StringUtils.isEmpty(orgCode)) { throw new IllegalArgumentException("Orginazation code must not be null or empty"); } if (StringUtils.isEmpty(getSudo)) { throw new IllegalArgumentException("Month must not be null or empty"); } if (StringUtils.isEmpty(sql)) { throw new IllegalArgumentException("Sql must not be null or empty"); } Connection connection = null; PreparedStatement preSmt = null; ResultSet rs = null; final String HAZELCAST_PURCHASES = "PURCHASES"; final String UNDERSCORE_CHAR = "_"; // Get a reference to the shared system metadata map as a cluster member // NOTE: this loads the map from the backing store and can take a long time for large collections Map<String, PurchaseBean> purchases = hzInstance.getMap(HAZELCAST_PURCHASES); if (hzInstance.getLifecycleService().isRunning()) { try { purchases.clear(); } catch (HazelcastInstanceNotActiveException ex) { logger.debug(ex.getMessage(), ex); } } try { connection = HibernateSessionManager.getConnection(); preSmt = connection.prepareStatement(sql); preSmt.setString(1, getSudo); preSmt.setString(2, orgCode); rs = preSmt.executeQuery(); while (rs.next()) { String srsCode = rs.getString("srsCode"); String ctgCode = rs.getString("ctgCode"); String wakuNum = rs.getString("wakuNum"); int updNo = rs.getInt("updNo"); int kingaku = rs.getBigDecimal("kingaku").intValue(); Date srDate = rs.getDate("srDate"); String gnrKbn1 = rs.getString("gnrKbn1"); StringBuilder keyBuilder = new StringBuilder(); keyBuilder.append(DateFormatUtil.format(srDate, DateFormat.DATE_SHORT_DAY)); keyBuilder.append(UNDERSCORE_CHAR); keyBuilder.append(srsCode); keyBuilder.append(UNDERSCORE_CHAR); keyBuilder.append(ctgCode); keyBuilder.append(UNDERSCORE_CHAR); keyBuilder.append(wakuNum); // New an instance PurchaseBean purchase = new PurchaseBean(srsCode, null, null, ctgCode, null, null, wakuNum, updNo, srDate, kingaku, gnrKbn1); purchases.put(keyBuilder.toString(), purchase); } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } finally { try { if (rs != null) { rs.close(); } if (preSmt != null) { preSmt.close(); } if (connection != null) { connection.close(); } } catch (SQLException ex) { logger.error(ex.getMessage(), ex); } } if (purchases.size() <= 0) { throw new ObjectNotFoundException( "Could not find any purchase in the database for the organization's code " + orgCode + " in month " + getSudo); } logger.info("Size of Hazelcast Map: {} items", purchases.size()); return purchases; }
From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Cette fonction permet de rcuprer l'historique d'un groupe * * @param ds/*w ww. ja v a2 s . c om*/ * @param idConcept * @param idThesaurus * @return */ public ArrayList<NodeGroup> getGroupHistoriqueAll(HikariDataSource ds, String idConcept, String idThesaurus) { Connection conn; Statement stmt; ArrayList<NodeGroup> nodeGroupList = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select idgroup, id_ark, idtypecode, idparentgroup, notation, modified, username from concept_group_historique, users " + "where idconcept = '" + idConcept + "'" + " and idthesaurus = '" + idThesaurus + "'" + " and concept_group_historique.id_user=users.id_user" + " order by modified DESC"; ResultSet resultSet = stmt.executeQuery(query); if (resultSet != null) { nodeGroupList = new ArrayList<>(); while (resultSet.next()) { NodeGroup nodeGroup = new NodeGroup(); nodeGroup.setIdUser(resultSet.getString("username")); nodeGroup.setModified(resultSet.getDate("modified")); nodeGroup.getConceptGroup().setId(resultSet.getInt("idgroup")); nodeGroup.getConceptGroup().setIdARk(resultSet.getString("id_ark")); nodeGroup.getConceptGroup().setIdthesaurus(idThesaurus); nodeGroup.getConceptGroup().setIdtypecode(resultSet.getString("idtypecode")); nodeGroup.getConceptGroup().setIdparentgroup(resultSet.getString("idparentgroup")); nodeGroup.getConceptGroup().setNotation(resultSet.getString("notation")); nodeGroup.getConceptGroup().setIdconcept(resultSet.getString("idconcept")); nodeGroupList.add(nodeGroup); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting All historique group of concept : " + idConcept, sqle); } return nodeGroupList; }
From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Cette fonction permet de rcuprer l'historique d'un groupe une date * prcise/*from w ww .j a v a 2s . c om*/ * * @param ds * @param idConcept * @param idThesaurus * @param date * @return */ public ArrayList<NodeGroup> getGroupHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, Date date) { Connection conn; Statement stmt; ArrayList<NodeGroup> nodeGroupList = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select idgroup, id_ark, idtypecode, idparentgroup, notation, modified, username from concept_group_historique, users " + "where idconcept = '" + idConcept + "'" + " and idthesaurus = '" + idThesaurus + "'" + " and concept_group_historique.id_user=users.id_user" + " and modified <= '" + date.toString() + "' order by modified DESC"; ResultSet resultSet = stmt.executeQuery(query); if (resultSet != null) { nodeGroupList = new ArrayList<>(); while (resultSet.next()) { NodeGroup nodeGroup = new NodeGroup(); nodeGroup.setIdUser(resultSet.getString("username")); nodeGroup.setModified(resultSet.getDate("modified")); nodeGroup.getConceptGroup().setId(resultSet.getInt("idgroup")); nodeGroup.getConceptGroup().setIdARk(resultSet.getString("id_ark")); nodeGroup.getConceptGroup().setIdthesaurus(idThesaurus); nodeGroup.getConceptGroup().setIdtypecode(resultSet.getString("idtypecode")); nodeGroup.getConceptGroup().setIdparentgroup(resultSet.getString("idparentgroup")); nodeGroup.getConceptGroup().setNotation(resultSet.getString("notation")); nodeGroup.getConceptGroup().setIdconcept(resultSet.getString("idconcept")); nodeGroupList.add(nodeGroup); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date historique group of concept : " + idConcept, sqle); } return nodeGroupList; }
From source file:GuestBookServlet.java
private void printComments(PrintWriter out, Locale loc) throws IOException { Connection conn = null;/* ww w .j a v a 2 s . c om*/ try { DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, loc); ResultSet results; Statement stmt; int rows, count; conn = DriverManager.getConnection(jdbcURL, connectionProperties); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); results = stmt.executeQuery("SELECT NAME, EMAIL, CMT_DATE, " + "COMMENT, COMMENT_ID " + "FROM COMMENT " + "ORDER BY CMT_DATE"); out.println("<dl>"); results.last(); results.next(); rows = results.getRow(); // pick a random row rows = random.nextInt() % rows; if (rows < 4) { // if the random row is less than 4, print the first 4 rows results.afterLast(); } else { // otherwise go to the specified row, print the prior 5 rows results.absolute(rows); } count = 0; // print up to 5 rows going backwards from the randomly // selected row while (results.previous() && (count < 5)) { String name, email, cmt; Date date; count++; name = results.getString(1); if (results.wasNull()) { name = "Unknown User"; } email = results.getString(2); if (results.wasNull()) { email = "user@host"; } date = results.getDate(3); if (results.wasNull()) { date = new Date((new java.util.Date()).getTime()); } cmt = results.getString(4); if (results.wasNull()) { cmt = "No comment."; } out.println("<dt><b>" + name + "</b> (" + email + ") on " + fmt.format(date) + "</dt>"); cmt = noXML(cmt); out.println("<dd> " + cmt + "</dd>"); } out.println("</dl>"); } catch (SQLException e) { out.println("A database error occurred: " + e.getMessage()); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } }
From source file:massbank.DatabaseManager.java
public Record getAccessionData(String accessionId, String contributor) { Record acc = new Record(contributor); try {/*from ww w . j a v a2s .co m*/ this.statementRECORD.setString(1, accessionId); ResultSet set = this.statementRECORD.executeQuery(); int compoundID = -1; int sampleID = -1; int instrumentID = -1; if (set.next()) { acc.ACCESSION(set.getString("ACCESSION")); acc.RECORD_TITLE(set.getString("RECORD_TITLE")); acc.DATE(set.getDate("DATE").toLocalDate()); acc.AUTHORS(set.getString("AUTHORS")); acc.LICENSE(set.getString("LICENSE")); acc.COPYRIGHT(set.getString("COPYRIGHT")); acc.PUBLICATION(set.getString("PUBLICATION")); compoundID = set.getInt("CH"); sampleID = set.getInt("SP"); instrumentID = set.getInt("AC_INSTRUMENT"); acc.AC_MASS_SPECTROMETRY_MS_TYPE(set.getString("AC_MASS_SPECTROMETRY_MS_TYPE")); acc.AC_MASS_SPECTROMETRY_ION_MODE(set.getString("AC_MASS_SPECTROMETRY_ION_MODE")); acc.PK_SPLASH(set.getString("PK_SPLASH")); this.statementAC_CHROMATOGRAPHY.setString(1, set.getString("ACCESSION")); this.statementAC_MASS_SPECTROMETRY.setString(1, set.getString("ACCESSION")); this.statementMS_DATA_PROCESSING.setString(1, set.getString("ACCESSION")); this.statementMS_FOCUSED_ION.setString(1, set.getString("ACCESSION")); this.statementCOMMENT.setString(1, set.getString("ACCESSION")); this.statementPEAK.setString(1, set.getString("ACCESSION")); this.statementPK_NUM_PEAK.setString(1, set.getString("ACCESSION")); this.statementANNOTATION_HEADER.setString(1, accessionId); ResultSet tmp = this.statementAC_CHROMATOGRAPHY.executeQuery(); List<Pair<String, String>> tmpList = new ArrayList<Pair<String, String>>(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.AC_CHROMATOGRAPHY(tmpList); tmp = this.statementAC_MASS_SPECTROMETRY.executeQuery(); tmpList.clear(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.AC_MASS_SPECTROMETRY(tmpList); tmp = this.statementMS_DATA_PROCESSING.executeQuery(); tmpList.clear(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.MS_DATA_PROCESSING(tmpList); tmp = this.statementMS_FOCUSED_ION.executeQuery(); tmpList.clear(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.MS_FOCUSED_ION(tmpList); tmp = this.statementCOMMENT.executeQuery(); List<String> tmpList2 = new ArrayList<String>(); while (tmp.next()) tmpList2.add(tmp.getString("COMMENT")); acc.COMMENT(tmpList2); tmp = this.statementANNOTATION_HEADER.executeQuery(); // int PK_ANNOTATION_HEADER_numberOfTokens = -1; if (tmp.next()) { String PK_ANNOTATION_HEADER = tmp.getString("HEADER"); String[] PK_ANNOTATION_HEADER_tokens = PK_ANNOTATION_HEADER.split(" "); acc.PK_ANNOTATION_HEADER(Arrays.asList(PK_ANNOTATION_HEADER_tokens)); // PK_ANNOTATION_HEADER_numberOfTokens = PK_ANNOTATION_HEADER_tokens.length; } tmp = this.statementPEAK.executeQuery(); // acc.add("PK$PEAK", null, "m/z int. rel.int."); while (tmp.next()) { acc.PK_PEAK_ADD_LINE(Arrays.asList((Double) tmp.getDouble("PK_PEAK_MZ"), (Double) (double) tmp.getFloat("PK_PEAK_INTENSITY"), (Double) (double) tmp.getShort("PK_PEAK_RELATIVE"))); String PK_ANNOTATION = tmp.getString("PK_ANNOTATION"); if (PK_ANNOTATION != null) acc.PK_ANNOTATION_ADD_LINE(Arrays.asList(PK_ANNOTATION.split(" "))); } tmp = this.statementPK_NUM_PEAK.executeQuery(); while (tmp.next()) { acc.PK_NUM_PEAK(Integer.valueOf(tmp.getInt("PK_NUM_PEAK"))); } } else throw new IllegalStateException("accessionId '" + accessionId + "' is not in database"); if (compoundID == -1) throw new IllegalStateException("compoundID is not set"); this.statementCOMPOUND.setInt(1, compoundID); set = this.statementCOMPOUND.executeQuery(); while (set.next()) { String formulaString = set.getString("CH_FORMULA"); IMolecularFormula m = MolecularFormulaManipulator.getMolecularFormula(formulaString, DefaultChemObjectBuilder.getInstance()); acc.CH_FORMULA(m); acc.CH_EXACT_MASS(set.getDouble("CH_EXACT_MASS")); String smilesString = set.getString("CH_SMILES"); if (smilesString.equals("N/A")) acc.CH_SMILES(new AtomContainer()); else { IAtomContainer c = new SmilesParser(DefaultChemObjectBuilder.getInstance()) .parseSmiles(smilesString); acc.CH_SMILES(c); } String iupacString = set.getString("CH_IUPAC"); if (iupacString.equals("N/A")) acc.CH_IUPAC(new AtomContainer()); else { // Get InChIToStructure InChIToStructure intostruct = InChIGeneratorFactory.getInstance() .getInChIToStructure(iupacString, DefaultChemObjectBuilder.getInstance()); INCHI_RET ret = intostruct.getReturnStatus(); if (ret == INCHI_RET.WARNING) { // Structure generated, but with warning message System.out.println(acc.ACCESSION() + ": InChI warning: " + intostruct.getMessage()); } else if (ret != INCHI_RET.OKAY) { // Structure generation failed throw new IllegalArgumentException( "Can not parse INCHI string in \"CH$IUPAC\" field. Structure generation failed: " + ret.toString() + " [" + intostruct.getMessage() + "] for " + iupacString); } IAtomContainer iupac = intostruct.getAtomContainer(); acc.CH_IUPAC(iupac); } // TODO CH$CDK_DEPICT_SMILES // TODO CH$CDK_DEPICT_GENERIC_SMILES // TODO CH$CDK_DEPICT_STRUCTURE_SMILES // acc.add("CH$CDK_DEPICT_SMILES", null, set.getString("CH_CDK_DEPICT_SMILES")); // acc.add("CH$CDK_DEPICT_GENERIC_SMILES", null, set.getString("CH_CDK_DEPICT_GENERIC_SMILES")); // acc.add("CH$CDK_DEPICT_STRUCTURE_SMILES", null, set.getString("CH_CDK_DEPICT_STRUCTURE_SMILES")); } this.statementCH_LINK.setInt(1, compoundID); set = this.statementCH_LINK.executeQuery(); List<Pair<String, String>> tmpList = new ArrayList<Pair<String, String>>(); while (set.next()) { tmpList.add(Pair.of(set.getString("DATABASE_NAME"), set.getString("DATABASE_ID"))); } acc.CH_LINK(tmpList); this.statementCOMPOUND_COMPOUND_CLASS.setInt(1, compoundID); set = this.statementCOMPOUND_COMPOUND_CLASS.executeQuery(); List<String> tmpList2 = new ArrayList<String>(); while (set.next()) { this.statementCOMPOUND_CLASS.setInt(1, set.getInt("CLASS")); ResultSet tmp = this.statementCOMPOUND_CLASS.executeQuery(); while (tmp.next()) { tmpList2.add(tmp.getString("CH_COMPOUND_CLASS")); } } acc.CH_COMPOUND_CLASS(tmpList2); this.statementCOMPOUND_NAME.setInt(1, compoundID); set = this.statementCOMPOUND_NAME.executeQuery(); tmpList2.clear(); while (set.next()) { this.statementNAME.setInt(1, set.getInt("NAME")); ResultSet tmp = this.statementNAME.executeQuery(); while (tmp.next()) { tmpList2.add(tmp.getString("CH_NAME")); } } acc.CH_NAME(tmpList2); this.statementSAMPLE.setInt(1, sampleID); set = this.statementSAMPLE.executeQuery(); if (set.next()) { acc.SP_SCIENTIFIC_NAME(set.getString("SP_SCIENTIFIC_NAME")); acc.SP_LINEAGE(set.getString("SP_LINEAGE")); this.statementSP_LINK.setInt(1, set.getInt("ID")); ResultSet tmp = this.statementSP_LINK.executeQuery(); tmpList.clear(); while (tmp.next()) { String spLink = tmp.getString("SP_LINK"); String[] tokens = spLink.split(" "); tmpList.add(Pair.of(tokens[0], tokens[1])); } acc.SP_LINK(tmpList); this.statementSP_SAMPLE.setInt(1, set.getInt("ID")); tmp = this.statementSP_SAMPLE.executeQuery(); tmpList2.clear(); while (tmp.next()) { tmpList2.add(tmp.getString("SP_SAMPLE")); } acc.SP_SAMPLE(tmpList2); } if (instrumentID == -1) throw new IllegalStateException("instrumentID is not set"); this.statementINSTRUMENT.setInt(1, instrumentID); set = this.statementINSTRUMENT.executeQuery(); if (set.next()) { acc.AC_INSTRUMENT(set.getString("AC_INSTRUMENT")); acc.AC_INSTRUMENT_TYPE(set.getString("AC_INSTRUMENT_TYPE")); } else throw new IllegalStateException("instrumentID is not in database"); } catch (Exception e) { System.out.println("error: " + accessionId); e.printStackTrace(); return null; } // this.openConnection(); return acc; }
From source file:com.sfs.whichdoctor.dao.RelationshipDAOImpl.java
/** * Load relationship from the supplied dataset. * * @param rs the rs//from w ww .j av a 2 s.c o m * @param loadDetails the load details * @return the relationship bean * * @throws SQLException the SQL exception */ private RelationshipBean loadRelationship(final ResultSet rs, final BuilderBean loadDetails) throws SQLException { // Create relationship bean and fill with dataset info. RelationshipBean relationship = new RelationshipBean(); relationship.setGUID(rs.getInt("GUID")); relationship.setReferenceGUID(rs.getInt("ReferenceGUID")); relationship.setRelationshipClass(rs.getString("RelationshipClass")); relationship.setRelationshipType(rs.getString("RelationshipType")); relationship.setHierarchy(rs.getInt("Hierarchy")); relationship.setISBMapping(rs.getString("ISBMapping")); relationship.setIdentifier(rs.getString("Identifier")); relationship.setName(rs.getString("Name")); relationship.setRotationGUID(rs.getInt("RotationGUID")); try { relationship.setEndDate(rs.getDate("EndDate")); } catch (SQLException e) { dataLogger.info("Error parsing EndDate date: " + e.getMessage()); } try { relationship.setModifiedDate(rs.getDate("Modified")); } catch (SQLException e) { dataLogger.info("Error parsing Modified date: " + e.getMessage()); } if (loadDetails.getBoolean("PERSON")) { try { PersonBean person = this.personDAO.loadGUID(relationship.getGUID()); relationship.setPerson(person); } catch (WhichDoctorDaoException wde) { dataLogger.error("Error loading person for relationship: " + wde.getMessage()); } } if (loadDetails.getBoolean("RELATED_PERSON")) { try { PersonBean person = this.personDAO.loadGUID(relationship.getReferenceGUID()); relationship.setRelatedPerson(person); } catch (WhichDoctorDaoException wde) { dataLogger.error("Error loading related person for relationship: " + wde.getMessage()); } } return relationship; }
From source file:com.nway.spring.jdbc.bean.JavassistBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, StringBuilder handler) throws SQLException { if (propType.equals(String.class)) { handler.append("bean.").append(writer).append("(").append("$1.getString(").append(index).append("));"); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getInt(").append(index).append("));"); return rs.getInt(index); } else if (propType.equals(Integer.class)) { handler.append("bean.").append(writer).append("(").append("integerValue($1.getInt(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getLong(").append(index).append("));"); return rs.getLong(index); } else if (propType.equals(Long.class)) { handler.append("bean.").append(writer).append("(").append("longValue($1.getLong(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { handler.append("bean.").append(writer).append("(").append("$1.getDate(").append(index).append("));"); return rs.getDate(index); } else if (propType.equals(java.util.Date.class) || propType.equals(Timestamp.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTimestamp(").append(index) .append("));"); return rs.getTimestamp(index); } else if (propType.equals(Double.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getDouble(").append(index).append("));"); return rs.getDouble(index); } else if (propType.equals(Double.class)) { handler.append("bean.").append(writer).append("(").append("doubleValue($1.getDouble(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getFloat(").append(index).append("));"); return rs.getFloat(index); } else if (propType.equals(Float.class)) { handler.append("bean.").append(writer).append("(").append("floatValue($1.getFloat(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Time.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTime(").append(index).append("));"); return rs.getTime(index); } else if (propType.equals(Boolean.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getBoolean(").append(index).append("));"); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { handler.append("bean.").append(writer).append("(").append("booleanValue($1.getBoolean(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(byte[].class)) { handler.append("bean.").append(writer).append("(").append("$1.getBytes(").append(index).append("));"); return rs.getBytes(index); } else if (BigDecimal.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBigDecimal(").append(index) .append("));"); return rs.getBigDecimal(index); } else if (Blob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBlob(").append(index).append("));"); return rs.getBlob(index); } else if (Clob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getClob(").append(index).append("));"); return rs.getClob(index); } else if (propType.equals(Short.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getShort(").append(index).append("));"); return rs.getShort(index); } else if (propType.equals(Short.class)) { handler.append("bean.").append(writer).append("(").append("shortValue($1.getShort(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getByte(").append(index).append("));"); return rs.getByte(index); } else if (propType.equals(Byte.class)) { handler.append("bean.").append(writer).append("(").append("byteValue($1.getByte(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Byte.class); } else {// w w w . ja v a 2 s .c om handler.append("bean.").append(writer).append("(").append("(").append(propType.getName()).append(")") .append("$1.getObject(").append(index).append("));"); return rs.getObject(index); } }
From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java
@Override public List<Auction> getAuctions(final int start, final int length, final String sort, final String dir) { List<Auction> objs = Lists.newArrayList(); Connection conn = null;/* w w w . java 2 s.c o m*/ CallableStatement stmt = null; ResultSet rs = null; try { conn = _dataSource.getConnection(); stmt = conn.prepareCall("{call SP_GETAUCTIONS (?,?,?,?)}"); stmt.setInt(1, start); stmt.setInt(2, length); stmt.setString(3, sort); stmt.setString(4, dir); rs = stmt.executeQuery(); while (rs.next()) { AuctionBuilder builder = Auction.newBuilder().setUid(rs.getInt("UID")) .setName(rs.getString("NAME")); Date startdate = rs.getDate("STARTDATE"); if (startdate != null) { builder.setStartDate(startdate.getTime()); } Date enddate = rs.getDate("ENDDATE"); if (enddate != null) { builder.setEndDate(enddate.getTime()); } builder.setLogoUrl(rs.getString("LOGOURL")); builder.setColor(rs.getString("COLOR")); objs.add(builder.build()); } } catch (SQLException e) { LOG.error(Throwables.getStackTraceAsString(e)); } finally { DbUtils.closeQuietly(conn, stmt, rs); } if (LOG.isDebugEnabled()) { LOG.debug("AUCTION [method:{} result:{}]", new Object[] { "get", objs.size() }); } return ImmutableList.copyOf(objs); }
From source file:org.apache.tajo.storage.jdbc.JdbcScanner.java
protected void convertTuple(ResultSet resultSet, VTuple tuple) { try {/*from w w w. j a v a 2s.c o m*/ for (int column_idx = 0; column_idx < targets.length; column_idx++) { final Column c = targets[column_idx]; final int resultIdx = column_idx + 1; switch (c.getDataType().getType()) { case INT1: case INT2: tuple.put(column_idx, DatumFactory.createInt2(resultSet.getShort(resultIdx))); break; case INT4: tuple.put(column_idx, DatumFactory.createInt4(resultSet.getInt(resultIdx))); break; case INT8: tuple.put(column_idx, DatumFactory.createInt8(resultSet.getLong(resultIdx))); break; case FLOAT4: tuple.put(column_idx, DatumFactory.createFloat4(resultSet.getFloat(resultIdx))); break; case FLOAT8: tuple.put(column_idx, DatumFactory.createFloat8(resultSet.getDouble(resultIdx))); break; case CHAR: tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx))); break; case VARCHAR: case TEXT: // TODO - trim is unnecessary in many cases, so we can use it for certain cases tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx).trim())); break; case DATE: final Date date = resultSet.getDate(resultIdx); tuple.put(column_idx, DatumFactory.createDate(1900 + date.getYear(), 1 + date.getMonth(), date.getDate())); break; case TIME: final Time time = resultSet.getTime(resultIdx); tuple.put(column_idx, new TimeDatum( DateTimeUtil.toTime(time.getHours(), time.getMinutes(), time.getSeconds(), 0))); break; case TIMESTAMP: tuple.put(column_idx, DatumFactory .createTimestampDatumWithJavaMillis(resultSet.getTimestamp(resultIdx).getTime())); break; case BINARY: case VARBINARY: case BLOB: tuple.put(column_idx, DatumFactory.createBlob(resultSet.getBytes(resultIdx))); break; default: throw new TajoInternalError(new UnsupportedDataTypeException(c.getDataType().getType().name())); } } } catch (SQLException s) { throw new TajoInternalError(s); } }
From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, String processorName, String beanName, MethodVisitor mv) throws SQLException { if (propType.equals(String.class)) { visitMethod(mv, index, beanName, "Ljava/lang/String;", "getString", writer); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { visitMethod(mv, index, beanName, "I", "getInt", writer); return rs.getInt(index); } else if (propType.equals(Integer.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_INTEGER, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { visitMethod(mv, index, beanName, "J", "getLong", writer); return rs.getLong(index); } else if (propType.equals(Long.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_LONG, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Date;", "getDate", writer); return rs.getDate(index); } else if (propType.equals(java.util.Date.class)) { visitMethodCast(mv, index, beanName, PROPERTY_TYPE_DATE, "java/util/Date", writer); return rs.getTimestamp(index); } else if (propType.equals(Timestamp.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Timestamp;", "getTimestamp", writer); return rs.getTimestamp(index); } else if (propType.equals(Time.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Time;", "getTime", writer); return rs.getTime(index); } else if (propType.equals(Double.TYPE)) { visitMethod(mv, index, beanName, "D", "getDouble", writer); return rs.getDouble(index); } else if (propType.equals(Double.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_DOUBLE, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { visitMethod(mv, index, beanName, "F", "getFloat", writer); return rs.getFloat(index); } else if (propType.equals(Float.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_FLOAT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Boolean.TYPE)) { visitMethod(mv, index, beanName, "Z", "getBoolean", writer); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BOOLEAN, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(Clob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Clob;", "getClob", writer); return rs.getClob(index); } else if (propType.equals(Blob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Blob;", "getBlob", writer); return rs.getBlob(index); } else if (propType.equals(byte[].class)) { visitMethod(mv, index, beanName, "[B", "getBytes", writer); return rs.getBytes(index); } else if (propType.equals(Short.TYPE)) { visitMethod(mv, index, beanName, "S", "getShort", writer); return rs.getShort(index); } else if (propType.equals(Short.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_SHORT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { visitMethod(mv, index, beanName, "B", "getByte", writer); return rs.getByte(index); } else if (propType.equals(Byte.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BYTE, writer, processorName); return rs.getByte(index); } else {//from w ww . j a v a 2 s.c o m visitMethodCast(mv, index, beanName, PROPERTY_TYPE_OTHER, propType.getName().replace('.', '/'), writer); return rs.getObject(index); } }