List of usage examples for java.sql ResultSet getLong
long getLong(String columnLabel) throws SQLException;
ResultSet
object as a long
in the Java programming language. From source file:net.bhira.sample.api.jdbc.CompanyRowMapper.java
/** * Constructor for CompanyRowMapper that creates an instance of * {@link net.bhira.sample.model.Company} from row represented by rowNum in the given ResultSet. * //from w w w. jav a2 s.c o m * @param rs * an instance of ResultSet to be processed. * @param rowNum * integer representing the row number in ResultSet. */ @Override public Company mapRow(ResultSet rs, int rowNum) throws SQLException { Company company = new Company(); company.setId(rs.getLong("id")); company.setName(rs.getString("name")); company.setIndustry(rs.getString("industry")); company.setBillingAddress(rs.getString("billingaddr")); company.setShippingAddress(rs.getString("shippingaddr")); company.setCreated(rs.getTimestamp("created")); company.setModified(rs.getTimestamp("modified")); company.setCreatedBy(rs.getString("createdby")); company.setModifiedBy(rs.getString("modifiedby")); return company; }
From source file:org.inbio.ait.jdbc.mapper.CountrytiMapper.java
@Override public Countryti mapRow(ResultSet rs, int rowNum) throws SQLException { Countryti c = new Countryti(); //Mandatory data c.setCountryId(rs.getLong(ph.getCountryId())); c.setIndicatorId(rs.getLong(ph.getIndicatorId())); c.setTaxonScientificName(rs.getString(ph.getTaxonScientificName())); return c;//w ww . j av a 2 s.co m }
From source file:com.carfinance.module.vehiclemanage.domain.VehicleMaintailRowMapper.java
public VehicleMaintail mapRow(ResultSet rs, int arg1) throws SQLException { VehicleMaintail vehicleMaintail = new VehicleMaintail(); vehicleMaintail.setId(rs.getLong("id")); vehicleMaintail.setCarframe_no(rs.getString("carframe_no")); vehicleMaintail.setEngine_no(rs.getString("engine_no")); vehicleMaintail.setLicense_plate(rs.getString("license_plate")); vehicleMaintail.setMaintain_date(rs.getDate("maintain_date")); vehicleMaintail.setMaintain_content(rs.getString("maintain_content")); vehicleMaintail.setMaintain_price(rs.getDouble("maintain_price")); vehicleMaintail.setCurrent_km(rs.getLong("current_km")); vehicleMaintail.setNext_maintain_km(rs.getLong("next_maintain_km")); vehicleMaintail.setUser_id(rs.getLong("user_id")); vehicleMaintail.setUser_name(rs.getString("user_name")); vehicleMaintail.setCreate_by(rs.getLong("create_by")); vehicleMaintail.setCreate_at(rs.getDate("create_at")); vehicleMaintail.setUpdate_by(rs.getLong("update_by")); vehicleMaintail.setUpdate_at(rs.getDate("update_at")); return vehicleMaintail; }
From source file:org.ambraproject.doi.JdbcResolverService.java
@Override public AnnotationInfo getAnnotationInfo(String doi) { log.debug("looking up doi {} in Annotation table", doi); try {/*from w w w . j a v a 2 s .c o m*/ return (AnnotationInfo) jdbcTemplate.query("select an.annotationID, a.doi, an.type from annotation an " + " inner join article a on an.articleID = a.articleID " + " where an.annotationURI = ?", new Object[] { doi }, new RowMapper() { @Override public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return new AnnotationInfo(rs.getLong(1), //annotationId rs.getString(2), //article doi rs.getString(3) //type ); } }).get(0); } catch (IndexOutOfBoundsException e) { //no annotation return null; } }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** Execute an SQL statement and return the single long in the result set. * * @param s A prepared statement/* www .j ava 2 s.c o m*/ * @return The long result, or null if the result was a null value * Note that a null value is not the same as no result rows. * @throws IOFailure if the statement didn't result in exactly one row with * a long or null value */ public static Long selectLongValue(PreparedStatement s) { ArgumentNotValid.checkNotNull(s, "PreparedStatement s"); try { ResultSet res = s.executeQuery(); if (!res.next()) { throw new IOFailure("No results from " + s); } Long resultLong = res.getLong(1); if (res.wasNull()) { resultLong = null; } if (res.next()) { throw new IOFailure("Too many results from " + s); } return resultLong; } catch (SQLException e) { throw new IOFailure( "SQL error executing statement " + s + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } }
From source file:org.flywaydb.test.sample.spring3.BaseDBHelper.java
/** * Simple counter query to have simple test inside test methods. * * @return number of customer in database * @throws Exception/*from w ww. ja v a 2s .com*/ */ public int countCustomer() throws Exception { int result = -1; Statement stmt = con.createStatement(); String query = "select count(*) from Customer"; ResultSet rs = stmt.executeQuery(query); rs.next(); Long cnt = rs.getLong(1); result = cnt.intValue(); rs.close(); stmt.close(); return result; }
From source file:com.exploringspatial.com.exploringspatial.dao.mapping.CodeDefinitionRowMapper.java
@Override public CodeDefinition mapRow(ResultSet resultSet, int i) throws SQLException { final CodeDefinition codeDefinition = new CodeDefinition(); codeDefinition.setCodeDefinitionPk(resultSet.getLong(CodeDefinitionColumns.CODE_DEFINITION_PK.name())); codeDefinition.setCodeCategoryPk(resultSet.getLong(CodeDefinitionColumns.CODE_CATEGORY_PK.name())); codeDefinition.setCode(resultSet.getInt(CodeDefinitionColumns.CODE.name())); codeDefinition.setDefinition(resultSet.getString(CodeDefinitionColumns.DEFINITION.name())); return codeDefinition; }
From source file:org.flywaydb.test.sample.helper.BaseDBHelper.java
/** * Simple counter query to have simple test inside test methods. * //from ww w. ja v a 2 s .co m * @return number of customer in database * @throws Exception */ public int countCustomer() throws Exception { int result = -1; Statement stmt = con.createStatement(); String query = "select count(*) from Customer"; ResultSet rs = stmt.executeQuery(query); rs.next(); Long cnt = rs.getLong(1); result = cnt.intValue(); rs.close(); stmt.close(); return result; }
From source file:dao.DatasetColumnRowMapper.java
@Override public DatasetColumn mapRow(ResultSet rs, int rowNum) throws SQLException { Long id = rs.getLong(FIELD_ID_COLUMN); int sortID = rs.getInt(SORT_ID_COLUMN); int parentSortID = rs.getInt(PARENT_SORT_ID_COLUMN); String dataType = rs.getString(DATA_TYPE_COLUMN); String fieldName = rs.getString(FIELD_NAME_COLUMN); String comment = rs.getString(COMMENT_COLUMN); String strPartitioned = rs.getString(PARTITIONED_COLUMN); Long commentCount = rs.getLong(COMMENT_COUNT_COLUMN); boolean partitioned = false; if (StringUtils.isNotBlank(strPartitioned) && strPartitioned.equalsIgnoreCase("y")) { partitioned = true;/*w w w.j a va 2 s. c om*/ } String strIndexed = rs.getString(INDEXED_COLUMN); boolean indexed = false; if (StringUtils.isNotBlank(strIndexed) && strIndexed.equalsIgnoreCase("y")) { indexed = true; } String strNullable = rs.getString(NULLABLE_COLUMN); boolean nullable = false; if (StringUtils.isNotBlank(strNullable) && strNullable.equalsIgnoreCase("y")) { nullable = true; } String strDistributed = rs.getString(DISTRIBUTED_COLUMN); boolean distributed = false; if (StringUtils.isNotBlank(strDistributed) && strDistributed.equalsIgnoreCase("y")) { distributed = true; } DatasetColumn datasetColumn = new DatasetColumn(); datasetColumn.id = id; datasetColumn.sortID = sortID; datasetColumn.parentSortID = parentSortID; datasetColumn.fieldName = fieldName; datasetColumn.dataType = dataType; datasetColumn.distributed = distributed; datasetColumn.partitioned = partitioned; datasetColumn.indexed = indexed; datasetColumn.nullable = nullable; datasetColumn.comment = comment; datasetColumn.commentCount = commentCount; datasetColumn.treeGridClass = "treegrid-" + Integer.toString(datasetColumn.sortID); if (datasetColumn.parentSortID != 0) { datasetColumn.treeGridClass += " treegrid-parent-" + Integer.toString(datasetColumn.parentSortID); } return datasetColumn; }
From source file:com.ccoe.build.dal.SessionMapper.java
public Session mapRow(ResultSet rs, int arg1) throws SQLException { Session session = new Session(); session.setDuration(rs.getLong("duration")); session.setEnvironment(rs.getString("environment")); session.setJavaVersion(rs.getString("java_version")); session.setMavenVersion(rs.getString("maven_version")); session.setStartTime(rs.getDate("start_time")); session.setUserName(rs.getString("user_name")); session.setStatus(rs.getString("status")); session.setGoals(rs.getString("goals")); session.setAppName(rs.getString("pool_name")); session.setMachineName(rs.getString("machine_name")); Clob stacktrace = rs.getClob("full_stacktrace"); if (stacktrace != null) { session.setFullStackTrace(stacktrace.getSubString(1, (int) stacktrace.length())); }/* w w w.j av a 2s . co m*/ session.setExceptionMessage(rs.getString("cause")); session.setCategory(rs.getString("category")); session.setId(rs.getInt("id")); session.setFilter(rs.getString("filter")); return session; }