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:dk.netarkivet.common.utils.DBUtils.java
/** Execute an SQL statement and return the list of strings -> id mappings * in its result set.//from w ww. j a va2 s. com * * NB: the provided connection is not closed. * * @param connection connection to the database. * @param query the given sql-query (must not be null or empty string) * @param args The arguments to insert into this query * @throws SQLException If this query fails * @return the list of strings -> id mappings */ public static Map<String, Long> selectStringLongMap(Connection connection, String query, Object... args) throws SQLException { ArgumentNotValid.checkNotNull(connection, "Connection connection"); ArgumentNotValid.checkNotNullOrEmpty(query, "String query"); ArgumentNotValid.checkNotNull(args, "Object... args"); PreparedStatement s = null; try { s = prepareStatement(connection, query, args); ResultSet result = s.executeQuery(); Map<String, Long> results = new HashMap<String, Long>(); while (result.next()) { String resultString = result.getString(1); long resultLong = result.getLong(2); if ((resultString == null) || (resultLong == 0L && result.wasNull())) { String warning = "NULL pointers found in entry (" + resultString + "," + resultLong + ") in resultset from query: " + query; log.warn(warning); } results.put(resultString, resultLong); } return results; } finally { closeStatementIfOpen(s); } }
From source file:ems.emsystem.dao.JDBCEmployeeDAOImpl.java
private Employee getEmployeeFromResultSet(ResultSet rs) throws SQLException { Employee em = new Employee(); em.setId(rs.getLong("ID")); em.setActive(rs.getBoolean("ACTIVE")); em.setBirthdate(rs.getDate("BIRTHDATE")); em.setFirstname(rs.getString("FIRSTNAME")); em.setLastname(rs.getString("LASTNAME")); em.setSalary(rs.getDouble("SALARY")); long dep_id = rs.getLong("DEPARTMENT"); Department dep = departmentDAO.getDepartment(dep_id); em.setDepartment(dep);//from ww w . j a v a2 s. c om return em; }
From source file:org.jasig.schedassist.impl.owner.PublicProfileRowMapper.java
/** * Expects following columns (in addition to all columns expected by {@link PublicProfileIdRowMapper#mapRow(ResultSet, int)}: <pre>/*from w ww . j a v a2 s. c om*/ profile_description noteboard </pre> * * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) */ @Override public PublicProfile mapRow(ResultSet rs, int rowNum) throws SQLException { PublicProfile profile = new PublicProfile(); profile.setPublicProfileId(profileIdMapper.mapRow(rs, rowNum)); profile.setOwnerId(rs.getLong("owner_id")); profile.setDescription(rs.getString("profile_description")); profile.setOwnerNoteboard(rs.getString("noteboard")); return profile; }
From source file:com.l2jfree.gameserver.AutoAnnouncements.java
private void restore() { Connection conn = null;/*from w ww . j a v a 2s .co m*/ try { conn = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = conn .prepareStatement("SELECT initial, delay, cycle, memo FROM auto_announcements"); ResultSet data = statement.executeQuery(); while (data.next()) { final long initial = data.getLong("initial"); final long delay = data.getLong("delay"); final int repeat = data.getInt("cycle"); final String[] memo = data.getString("memo").split("\n"); _announcers.add(new AutoAnnouncer(memo, repeat, initial, delay)); } data.close(); statement.close(); } catch (Exception e) { _log.fatal("AutoAnnoucements: Failed to load announcements data.", e); } finally { L2DatabaseFactory.close(conn); } _log.info("AutoAnnoucements: Loaded " + _announcers.size() + " Auto Annoucement Data."); }
From source file:eu.trentorise.smartcampus.resourceprovider.jdbc.JdbcServices.java
@Override public User loadUserByUserId(String userId) { return queryForObject(selectUserSql, new RowMapper<User>() { @Override/*from ww w .j a v a2s . c o m*/ public User mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); user.setId("" + rs.getLong("id")); user.setName(rs.getString("name")); user.setSurname(rs.getString("surname")); user.setSocialId(rs.getString("social_id")); return user; } }, Long.parseLong(userId)); }
From source file:eu.trentorise.smartcampus.resourceprovider.jdbc.JdbcServices.java
@Override public User loadUserBySocialId(String socialId) { return queryForObject(selectUserSocialIdSql, new RowMapper<User>() { @Override//from w w w .j ava 2s. com public User mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); user.setId("" + rs.getLong("id")); user.setName(rs.getString("name")); user.setSurname(rs.getString("surname")); user.setSocialId(rs.getString("social_id")); return user; } }, socialId); }
From source file:escuela.AlumnoDaoJdbc.java
@Override public Alumno mapRow(ResultSet rs, int rowNum) throws SQLException { Alumno alumno = new Alumno(); alumno.setId(rs.getLong("ID")); alumno.setMatricula("MATRICULA"); alumno.setNombre(rs.getString("NOMBRE")); alumno.setApellido(rs.getString("APELLIDO")); return alumno; }
From source file:org.tec.webapp.jdbc.entity.support.IdentifierCallback.java
/** {@inheritDoc} */ @Override()//from w w w . j a v a 2 s. c o m public Long doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ResultSet generatedKeys = null; try { ps.execute(); generatedKeys = ps.getGeneratedKeys(); if (generatedKeys.next()) { return Long.valueOf(generatedKeys.getLong(1)); } else { throw new SQLException("Unable to insert new record " + ps.toString()); } } finally { if (generatedKeys != null) { generatedKeys.close(); } } }
From source file:org.apache.lucene.store.jdbc.handler.AbstractFileEntryHandler.java
public long fileLength(final String name) throws IOException { return ((Long) jdbcTemplate.execute(table.sqlSelectSizeByName(), new PreparedStatementCallback() { @Override//www.j a va 2 s . c o m public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.setFetchSize(1); ps.setString(1, name); ResultSet rs = ps.executeQuery(); if (rs.next()) { return new Long(rs.getLong(1)); } return new Long(0L); } })).longValue(); }
From source file:lcn.module.batch.web.guide.support.StagingItemReader.java
/** * BATCH_STAGING? ID? .//from w w w . j a v a 2 s. c o m * @return List<Long> :BATCH_STAGING? Id */ private List<Long> retrieveKeys() { synchronized (lock) { return jdbcTemplate.query( "SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID", new ParameterizedRowMapper<Long>() { public Long mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getLong(1); } }, stepExecution.getJobExecution().getJobId(), StagingItemWriter.NEW); } }