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:dao.ImpactDatasetRowMapper.java
@Override public ImpactDataset mapRow(ResultSet rs, int rowNum) throws SQLException { String storageType = rs.getString(STORAGE_TYPE_COLUMN); String filePath = rs.getString(OBJECT_NAME_COLUMN); Long id = rs.getLong(DATASET_ID_COLUMN); LineagePathInfo lineagePathInfo = new LineagePathInfo(); lineagePathInfo.storageType = storageType; lineagePathInfo.filePath = filePath; ImpactDataset impactDataset = new ImpactDataset(); impactDataset.urn = Lineage.convertToURN(lineagePathInfo); impactDataset.id = id;/*ww w .j a v a2 s. co m*/ if (impactDataset.id != null && impactDataset.id > 0) { impactDataset.isValidDataset = true; impactDataset.datasetUrl = "#/datasets/" + Long.toString(impactDataset.id); } else { impactDataset.isValidDataset = false; } if (StringUtils.isNotBlank(impactDataset.urn)) { int index = impactDataset.urn.lastIndexOf('/'); if (index != -1) { impactDataset.name = impactDataset.urn.substring(index + 1); } } return impactDataset; }
From source file:com.github.dbourdette.glass.log.joblog.jdbc.JdbcJobLogStore.java
private JobLog doMapRow(ResultSet rs, int rowNum) throws SQLException { JobLog jobLog = new JobLog(); jobLog.setExecutionId(rs.getLong("executionId")); jobLog.setLevel(JobLogLevel.valueOf(rs.getString("logLevel"))); jobLog.setDate(rs.getTimestamp("logDate")); jobLog.setJobClass(rs.getString("jobClass")); jobLog.setJobGroup(rs.getString("jobGroup")); jobLog.setJobName(rs.getString("jobName")); jobLog.setTriggerGroup(rs.getString("triggerGroup")); jobLog.setTriggerName(rs.getString("triggerName")); jobLog.setMessage(rs.getString("message")); jobLog.setStackTrace(rs.getString("stackTrace")); jobLog.setRootCause(rs.getString("rootCause")); return jobLog; }
From source file:com.spankr.tutorial.TestConnectionDAO.java
/** * @throws SQLException//from w w w . j av a 2 s . c om * */ @Test public void getSomeData() throws SQLException { Connection con = null; try { printActiveConnections(); con = ds.getConnection(); printActiveConnections(); Statement stmt = null; log.info("Creating sample_table"); stmt = con.createStatement(); stmt.execute( "CREATE TABLE sample_table (id INT IDENTITY, first_name VARCHAR(30), last_name VARCHAR(30), age INT)"); DbUtils.closeQuietly(stmt); PreparedStatement pstmt = null; log.info("Inserting a person into sample_table"); pstmt = con.prepareStatement("INSERT INTO sample_table VALUES (null, ?, ?, ?)"); pstmt.setString(1, "Bob"); pstmt.setString(2, "Haskins"); pstmt.setInt(3, 38); Assert.assertTrue(pstmt.executeUpdate() == 1); // success means exactly one row inserted DbUtils.closeQuietly(pstmt); log.info("Getting a count of rows in sample_table"); stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT count(1) from sample_table"); if (rs.next()) { long l = rs.getLong(1); assertTrue("Shouldn't get a zero count", l > 0); log.debug(String.format("Total records = %s", l)); } else { fail("Nothing returned from the database query"); } } catch (SQLException e) { fail("Unable to create the database table"); } finally { DbUtils.closeQuietly(con); printActiveConnections(); } }
From source file:io.apiman.manager.api.jdbc.handlers.ResponseStatsSummaryHandler.java
/** * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) *//*from w w w. j av a2s. c o m*/ @Override public ResponseStatsSummaryBean handle(ResultSet rs) throws SQLException { ResponseStatsSummaryBean rval = new ResponseStatsSummaryBean(); while (rs.next()) { String rtype = rs.getString(1); long count = rs.getLong(2); if (rtype == null) { rval.setTotal(rval.getErrors() + rval.getFailures() + count); } else if (rtype.equals("failure")) { //$NON-NLS-1$ rval.setTotal(rval.getTotal() + count); rval.setFailures(count); } else if (rtype.equals("error")) { //$NON-NLS-1$ rval.setTotal(rval.getTotal() + count); rval.setErrors(count); } } return rval; }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Return an iterator to a list of Longs. * @param connection an open 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 * @return an iterator to a list of Longs. *//*from ww w. j av a 2 s .c o m*/ public static Iterator<Long> selectLongIterator(Connection connection, String query, Object... args) { ArgumentNotValid.checkNotNull(connection, "Connection connection"); ArgumentNotValid.checkNotNullOrEmpty(query, "String query"); ArgumentNotValid.checkNotNull(args, "Object... args"); PreparedStatement s = null; try { s = prepareStatement(connection, 8192, query, args); ResultSet result = s.executeQuery(); Iterator<Long> results = new ResultSetIterator<Long>(s, result) { @Override public Long filter(ResultSet result) { try { return result.getLong(1); } catch (SQLException e) { log.warn("Error retrieving long from resultset\n" + ExceptionUtils.getSQLExceptionCause(e), e); return 0L; } } }; return results; } catch (SQLException e) { closeStatementIfOpen(s); throw new IOFailure("Error preparing SQL statement " + query + " args " + Arrays.toString(args) + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } }
From source file:eionet.cr.dao.virtuoso.VirtuosoDeliveryFilterDAO.java
private void deleteOldestFilter(String username, int preserveRecent) throws DAOException { // Getting the id's of latest delivery filters List<Object> selectParams = new ArrayList<Object>(); selectParams.add(username);/*from w w w. j a v a2s . c o m*/ StringBuffer selectSql = new StringBuffer(); selectSql.append("SELECT TOP " + preserveRecent + " delivery_filter_id "); selectSql.append("FROM delivery_filter "); selectSql.append("WHERE username = ? "); selectSql.append("ORDER BY delivery_filter_id DESC"); List<Long> list = executeSQL(selectSql.toString(), selectParams, new SQLResultSetBaseReader<Long>() { @Override public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { Long id = rs.getLong("delivery_filter_id"); resultList.add(id); } }); // Deleting all the user filters except the latest ones List<Object> deleteParams = new ArrayList<Object>(); deleteParams.add(username); StringBuffer deleteSql = new StringBuffer(); deleteSql.append("DELETE FROM delivery_filter "); deleteSql.append("WHERE delivery_filter_id not in (" + StringUtils.join(list, ",") + ") "); deleteSql.append("AND username = ?"); executeSQL(deleteSql.toString(), deleteParams); }
From source file:com.ewcms.component.comment.dao.CommentDAO.java
private List<Reply> findReply(final Long commentId) { String sql = "Select * From component_comment_reply Where comment_id = ?"; Object[] params = { commentId }; return jdbcTemplate.query(sql, params, new RowMapper<Reply>() { @Override//w w w. j ava 2 s . co m public Reply mapRow(ResultSet rs, int rowNum) throws SQLException { Reply reply = new Reply(); reply.setId(rs.getLong("id")); reply.setCommentId(commentId); reply.setIp(rs.getString("ip")); reply.setUsername(rs.getString("username")); reply.setDate(rs.getTimestamp("date")); return reply; } }); }
From source file:com.googlecode.starflow.engine.repository.impl.ProcessInstanceRepositoryImpl.java
public ProcessInstance findProcessInstance(long processInstId) { return this.getJdbcTemplate().queryForObject(findProcessInstanceSQL, new RowMapper<ProcessInstance>() { @Override/*from w w w. j a v a 2s . co m*/ public ProcessInstance mapRow(ResultSet resultSet, int index) throws SQLException { ProcessInstance processInstance = new ProcessInstance(); processInstance.setProcessInstId(resultSet.getLong("processInstId")); processInstance.setProcessDefId(resultSet.getLong("processDefId")); processInstance.setProcessInstName(resultSet.getString("processInstName")); processInstance.setCreator(resultSet.getString("creator")); processInstance.setCreateTime(resultSet.getDate("createTime")); processInstance.setSubFlow(resultSet.getString("subFlow")); processInstance.setLimitNum(resultSet.getLong("limitNum")); processInstance.setCurrentState(resultSet.getInt("currentState")); processInstance.setMainProcInstId(resultSet.getLong("mainProcInstId")); processInstance.setParentProcInstId(resultSet.getLong("parentProcInstId")); processInstance.setActivityInstId(resultSet.getLong("activityInstId")); return processInstance; } }, processInstId); }
From source file:id.go.kemdikbud.tandajasa.dao.PegawaiDaoTest.java
@Test public void testHapus() throws Exception { DataSource ds = ctx.getBean(DataSource.class); Connection koneksiDatabase = ds.getConnection(); PreparedStatement ps = koneksiDatabase.prepareStatement("select count(*) as jumlah from pegawai"); ResultSet rsSebelum = ps.executeQuery(); Assert.assertTrue(rsSebelum.next()); Long jumlahRecordSebelum = rsSebelum.getLong(1); rsSebelum.close();//from w ww .j a v a2s. c o m PegawaiDao pd = (PegawaiDao) ctx.getBean("pegawaiDao"); Pegawai p = pd.cariById(100); Assert.assertNotNull(p); pd.delete(p); ResultSet rsSetelah = ps.executeQuery(); Assert.assertTrue(rsSetelah.next()); Long jumlahRecordSetelah = rsSetelah.getLong("jumlah"); rsSetelah.close(); koneksiDatabase.close(); Assert.assertEquals(new Long(jumlahRecordSebelum - 1), new Long(jumlahRecordSetelah)); }
From source file:com.duck8823.dao.PersonDao.java
public List<Person> list() throws SQLException { ResultSet rs = dataSource.getConnection().createStatement().executeQuery("SELECT id, name FROM person"); LinkedList<Person> result = new LinkedList<>(); while (rs.next()) { result.add(new Person(rs.getLong("id"), rs.getString("name"))); }// www. j a v a 2s.c om return result; }