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:es.emergya.bbdd.dao.RoutingHome.java
/** * Devuelve la lista de ids de la ruta desde vertice_origen a * vertice_destino./*from w w w . j a va 2 s . c o m*/ * * Utiliza la funcion shooting_star * * @param origin * @param goal * @return */ @Transactional(readOnly = true, rollbackFor = Throwable.class) private List<Long> shortest_path_shooting_star(final Long origin, final Long goal) { final List<Long> lista = new ArrayList<Long>(); try { Session currentSession = getSession(); CallableStatement consulta = currentSession.connection() .prepareCall("{call shortest_path_shooting_star(?,?,?,?,?)}"); consulta.setString(1, "SELECT " + id + "::integer as id, " + source + "::integer as source, " + target + "::integer as target, " + cost + " as cost," + reverse_cost + " as reverse_cost, " + "ST_X(ST_StartPoint(" + the_geom + ")) as x1," + "ST_Y(ST_StartPoint(" + the_geom + ")) as y1," + "ST_X(ST_EndPoint(" + the_geom + ")) as x2," + "ST_Y(ST_EndPoint(" + the_geom + ")) as y2," + rule + " as rule, " + to_cost + " as to_cost FROM " + table // + " order by " + id ); consulta.setInt(2, origin.intValue()); consulta.setInt(3, goal.intValue()); consulta.setBoolean(4, true); consulta.setBoolean(5, true); log.trace(consulta); ResultSet resultado = consulta.executeQuery(); while (resultado.next()) lista.add(resultado.getLong("edge_id")); } catch (Exception e) { log.error("No se pudo calcular la ruta", e); } return lista; }
From source file:com.flexive.ejb.beans.search.SearchEngineBean.java
/** * {@inheritDoc}// w w w . ja v a2 s . c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long getLastContentChange(boolean live) { Connection con = null; Statement stmt = null; try { con = Database.getDbConnection(); stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(StorageManager.getLastContentChangeStatement(live)); rs.next(); return rs.getLong(1); } catch (Exception e) { //noinspection ThrowableInstanceNeverThrown throw new FxLoadException(LOG, e, "ex.sqlSearch.lastContentChange", e).asRuntimeException(); } finally { Database.closeObjects(this.getClass(), con, stmt); } }
From source file:org.chimi.s4s.metainfo.mysql.MysqlMetaInfoDaoTest.java
private void assertData(String id, FileMetadata metadata) throws Throwable { Connection conn = dataSource.getConnection(); PreparedStatement pstmt = conn.prepareStatement("select * from FILE_METADATA where FILE_METADATA_ID = ?"); int idValue = Integer.parseInt(id); pstmt.setInt(1, idValue);/*from w ww. java2s .c o m*/ ResultSet rs = pstmt.executeQuery(); assertTrue(rs.next()); assertEquals(idValue, rs.getInt("FILE_METADATA_ID")); assertEquals(metadata.getServiceId(), rs.getString("SERVICE_ID")); assertEquals(metadata.getFileName(), rs.getString("FILE_NAME")); assertEquals(metadata.getLength(), rs.getLong("FILE_LENGTH")); assertEquals(metadata.getMimetype(), rs.getString("MIMETYPE")); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); assertEquals(format.format(metadata.getUploadTime()), format.format(rs.getTimestamp("UPLOAD_TIME"))); assertEquals(metadata.getFileId(), rs.getString("FILE_ID")); rs.close(); pstmt.close(); conn.close(); }
From source file:de.ingrid.importer.udk.strategy.v1.IDCStrategy1_0_4_fixInspireThemes.java
/** Get mapping of INSPIRE theme ids to according searchtermValues. */ private HashMap<Integer, Long> getThemeIdToSearchtermIdMap() throws Exception { HashMap<Integer, Long> map = new HashMap<Integer, Long>(); String sql = "SELECT id, entry_id " + "FROM searchterm_value " + "WHERE type = 'I' "; Statement st = jdbc.createStatement(); ResultSet rs = jdbc.executeQuery(sql, st); while (rs.next()) { int themeId = rs.getInt("entry_id"); long searchtermId = rs.getLong("id"); map.put(themeId, searchtermId);//from www. j a va 2 s . c o m } rs.close(); st.close(); return map; }
From source file:online.themixhub.demo.sql.impl.AccountMapper.java
public Account mapRow(ResultSet rs, int rowNum) throws SQLException { Account account = new Account(); account.setId(rs.getInt("id")); account.setPermission(rs.getInt("permission")); account.setDate(rs.getLong("date")); account.setEmail(rs.getString("email")); account.setUsername(rs.getString("username")); account.setPassword(rs.getString("password")); account.setFirstname(rs.getString("firstname")); account.setLastname(rs.getString("lastname")); account.setAddress_1(rs.getString("address_1")); account.setAddress_2(rs.getString("address_2")); account.setCity(rs.getString("city")); account.setState(rs.getString("state")); account.setCountry(rs.getString("country")); account.setZip(rs.getString("zip")); account.setPhone(rs.getString("phone")); return account; }
From source file:com.hs.mail.imap.dao.MySqlMailboxDao.java
public List<PhysMessage> getDanglingMessageIDList(long ownerID) { String sql = "SELECT m.physmessageid, p.internaldate FROM mailbox b, message m, physmessage p WHERE b.ownerid = ? AND m.physmessageid = p.id AND m.mailboxid = b.mailboxid GROUP BY m.physmessageid HAVING COUNT(m.physmessageid) = 1"; return (List<PhysMessage>) getJdbcTemplate().query(sql, new Object[] { new Long(ownerID) }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { PhysMessage pm = new PhysMessage(); pm.setPhysMessageID(rs.getLong("physmessageid")); pm.setInternalDate(new Date(rs.getTimestamp("internaldate").getTime())); return pm; }/* w w w.jav a 2 s . c o m*/ }); }
From source file:com.hs.mail.imap.dao.MySqlMailboxDao.java
public List<PhysMessage> getDanglingMessageIDList(long ownerID, long mailboxID) { String sql = "SELECT m.physmessageid, p.internaldate FROM message m, message n, physmessage p WHERE m.mailboxid = ? AND m.physmessageid = n.physmessageid AND m.physmessageid = p.id GROUP BY n.physmessageid HAVING COUNT(n.physmessageid) = 1"; return (List<PhysMessage>) getJdbcTemplate().query(sql, new Object[] { new Long(mailboxID) }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { PhysMessage pm = new PhysMessage(); pm.setPhysMessageID(rs.getLong("physmessageid")); pm.setInternalDate(new Date(rs.getTimestamp("internaldate").getTime())); return pm; }/*from w w w . java 2 s. c o m*/ }); }
From source file:com.emc.ecs.sync.service.DbService.java
protected boolean hasLongColumn(ResultSet rs, String name) throws SQLException { if (hasColumn(rs, name)) { rs.getLong(name); return !rs.wasNull(); }/* w w w.ja v a 2 s . c om*/ return false; }
From source file:de.iritgo.aktario.jdbc.LoadObject.java
/** * Load a list of iobjects.// w w w . j a v a2s.c om * * @param dataSource The data source to load from. * @param owner The owner of the list. * @param list the object list to load. */ public void loadList(final DataSource dataSource, DataObject owner, final IObjectList list) { try { QueryRunner query = new QueryRunner(dataSource); query.query("select elemType, elemId from IritgoObjectList where id=? and attribute=?", new Object[] { new Long(owner.getUniqueId()), list.getAttributeName() }, new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { while (rs.next()) { DataObject element = load(dataSource, rs.getString("elemType"), rs.getLong("elemId")); if (element != null) { list.add(element); } } return null; } }); } catch (SQLException x) { Log.logError("persist", "LoadObject", "Error while loading the object list " + list.getOwner().getTypeId() + "." + list.getAttributeName() + ": " + x); } }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java
/** * Retrieve a JDBC column value from a ResultSet, using the specified value * type.// www . jav a 2 s . c om * <p> * Uses the specifically typed ResultSet accessor methods, falling back to * {@link #getResultSetValue(java.sql.ResultSet, int)} for unknown types. * <p> * Note that the returned value may not be assignable to the specified * required type, in case of an unknown type. Calling code needs to deal * with this case appropriately, e.g. throwing a corresponding exception. * * @param rs is the ResultSet holding the data * @param index is the column index * @param requiredType the required value type (may be <code>null</code>) * @return the value object * @throws SQLException if thrown by the JDBC API */ private static String getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); } Object value = null; boolean wasNullCheck = false; // Explicitly extract typed value, as far as possible. if (String.class.equals(requiredType)) { value = rs.getString(index); } else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) { value = Boolean.valueOf(rs.getBoolean(index)); wasNullCheck = true; } else if (byte.class.equals(requiredType) || Byte.class.equals(requiredType)) { value = new Byte(rs.getByte(index)); wasNullCheck = true; } else if (short.class.equals(requiredType) || Short.class.equals(requiredType)) { value = new Short(rs.getShort(index)); wasNullCheck = true; } else if (int.class.equals(requiredType) || Integer.class.equals(requiredType)) { value = new Long(rs.getLong(index)); wasNullCheck = true; } else if (long.class.equals(requiredType) || Long.class.equals(requiredType)) { value = rs.getBigDecimal(index); wasNullCheck = true; } else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) { value = new Float(rs.getFloat(index)); wasNullCheck = true; } else if (double.class.equals(requiredType) || Double.class.equals(requiredType) || Number.class.equals(requiredType)) { value = new Double(rs.getDouble(index)); wasNullCheck = true; } else if (java.sql.Time.class.equals(requiredType)) { // try { // value = rs.getTime(index); // } catch (SQLException e) { value = rs.getString(index);// ?string0000Time // if (value == null && !rs.wasNull()) { // value = "00:00:00"; // // mysqlzeroDateTimeBehavior=convertToNull0null // } // } } else if (java.sql.Timestamp.class.equals(requiredType) || java.sql.Date.class.equals(requiredType)) { // try { // value = convertTimestamp(rs.getTimestamp(index)); // } catch (SQLException e) { // ?string0000-00-00 00:00:00Timestamp value = rs.getString(index); // if (value == null && !rs.wasNull()) { // value = "0000:00:00 00:00:00"; // // mysqlzeroDateTimeBehavior=convertToNull0null // } // } } else if (BigDecimal.class.equals(requiredType)) { value = rs.getBigDecimal(index); } else if (BigInteger.class.equals(requiredType)) { value = rs.getBigDecimal(index); } else if (Blob.class.equals(requiredType)) { value = rs.getBlob(index); } else if (Clob.class.equals(requiredType)) { value = rs.getClob(index); } else if (byte[].class.equals(requiredType)) { try { byte[] bytes = rs.getBytes(index); if (bytes == null) { value = null; } else { value = new String(bytes, "ISO-8859-1");// binaryiso-8859-1 } } catch (UnsupportedEncodingException e) { throw new SQLException(e); } } else { // Some unknown type desired -> rely on getObject. value = getResultSetValue(rs, index); } // Perform was-null check if demanded (for results that the // JDBC driver returns as primitives). if (wasNullCheck && (value != null) && rs.wasNull()) { value = null; } return (value == null) ? null : convertUtilsBean.convert(value); }