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:com.splicemachine.derby.impl.sql.execute.operations.export.ExportOperationIT.java
private void exportAndAssertExportResults(String exportSQL, long expectedExportRowCount) throws Exception { ResultSet resultSet = methodWatcher.executeQuery(exportSQL); assertTrue(resultSet.next());/*w w w.j a va 2 s . c o m*/ long exportedRowCount = resultSet.getLong(1); // long exportTimeMs = resultSet.getLong(2); assertEquals(expectedExportRowCount, exportedRowCount); // assertTrue(exportTimeMs >= 0); }
From source file:com.nextep.datadesigner.vcs.gui.dialog.UserLoginGUI.java
private void secureUserAuthentication(Connection conn) throws SQLException { PreparedStatement stmt = null; PreparedStatement updStmt = null; try {/*from www.j av a 2 s . c o m*/ stmt = conn.prepareStatement("SELECT " //$NON-NLS-1$ + " ru.user_id " //$NON-NLS-1$ + " , ru.password " //$NON-NLS-1$ + " , ru.secured_password " //$NON-NLS-1$ + "FROM rep_users ru " //$NON-NLS-1$ + "WHERE UPPER(ru.login) = ? "); //$NON-NLS-1$ stmt.setString(1, repositoryLogin); ResultSet rset = stmt.executeQuery(); if (rset.next()) { final Long userId = rset.getLong("user_id"); //$NON-NLS-1$ final String clearPassword = rset.getString("password"); //$NON-NLS-1$ String securedPassword = rset.getString("secured_password"); //$NON-NLS-1$ if (clearPassword != null && !"".equals(clearPassword)) { //$NON-NLS-1$ securedPassword = REPO_UI_SERVICE.encryptPassword(clearPassword.toUpperCase()); /* * Columns names in the SET clause cannot be qualified with an alias name * because it would fail in Postgres. */ updStmt = conn.prepareStatement("UPDATE REP_USERS ru " //$NON-NLS-1$ + " SET password = NULL " //$NON-NLS-1$ + " , secured_password = ? " //$NON-NLS-1$ + "WHERE ru.user_id = ? "); //$NON-NLS-1$ updStmt.setString(1, securedPassword); updStmt.setLong(2, userId); updStmt.execute(); } } } finally { try { if (updStmt != null) { updStmt.close(); } } catch (SQLException e) { LOGGER.error("Problems while closing resource: " + e.getMessage(), e); //$NON-NLS-1$ } try { if (stmt != null) { stmt.close(); } } catch (SQLException e) { LOGGER.error("Problems while closing resource: " + e.getMessage(), e); //$NON-NLS-1$ } } }
From source file:dk.netarkivet.harvester.datamodel.ScheduleDBDAO.java
/** * Read an existing schedule./*from w ww .j av a2 s. co m*/ * * @param scheduleName the name of the schedule * @return The schedule read * @throws ArgumentNotValid if schedulename is null or empty * @throws UnknownID if the schedule doesn't exist */ public synchronized Schedule read(String scheduleName) { ArgumentNotValid.checkNotNullOrEmpty(scheduleName, "String scheduleName"); Connection c = HarvestDBConnection.get(); PreparedStatement s = null; try { s = c.prepareStatement("SELECT schedule_id, comments, startdate, " + "enddate, maxrepeats, timeunit, " + "numtimeunits, anytime, onminute, " + "onhour, ondayofweek, ondayofmonth, edition " + "FROM schedules WHERE name = ?"); s.setString(1, scheduleName); ResultSet rs = s.executeQuery(); if (!rs.next()) { throw new UnknownID("No schedule named '" + scheduleName + "' found"); } long id = rs.getLong(1); boolean isTimedSchedule; String comments = rs.getString(2); Date startdate = DBUtils.getDateMaybeNull(rs, 3); Date enddate = DBUtils.getDateMaybeNull(rs, 4); int maxrepeats = rs.getInt(5); isTimedSchedule = rs.wasNull(); int timeunit = rs.getInt(6); int numtimeunits = rs.getInt(7); boolean anytime = rs.getBoolean(8); Integer minute = DBUtils.getIntegerMaybeNull(rs, 9); Integer hour = DBUtils.getIntegerMaybeNull(rs, 10); Integer dayofweek = DBUtils.getIntegerMaybeNull(rs, 11); Integer dayofmonth = DBUtils.getIntegerMaybeNull(rs, 12); log.debug("Creating frequency for " + "(timeunit,anytime,numtimeunits,hour, minute, dayofweek," + "dayofmonth) = (" + timeunit + ", " + anytime + "," + numtimeunits + "," + minute + "," + hour + "," + dayofweek + "," + dayofmonth + "," + ")"); Frequency freq = Frequency.getNewInstance(timeunit, anytime, numtimeunits, minute, hour, dayofweek, dayofmonth); long edition = rs.getLong(13); final Schedule schedule; if (isTimedSchedule) { schedule = Schedule.getInstance(startdate, enddate, freq, scheduleName, comments); } else { schedule = Schedule.getInstance(startdate, maxrepeats, freq, scheduleName, comments); } schedule.setID(id); schedule.setEdition(edition); return schedule; } catch (SQLException e) { throw new IOFailure( "SQL error reading schedule " + scheduleName + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } finally { DBUtils.closeStatementIfOpen(s); HarvestDBConnection.release(c); } }
From source file:de.nim.wscr.dao.MemberDAO.java
@Override public Member getMember(Member member) { Member toSearchForMember = new Member(); if (null != member) { try {/* w w w .j ava 2 s . c o m*/ String sql = "SELECT * FROM db1. member WHERE "; int paramCount = 0; if (member.getId() != null) { sql = sql + " ID = " + member.getId(); paramCount++; } if (StringUtils.isNotEmpty(member.getFirstName())) { if (paramCount > 0) { sql = sql + " AND"; } sql = sql + " FIRST_NAME = " + member.getFirstName(); paramCount++; } if (StringUtils.isNotEmpty(member.getLastName())) { if (paramCount > 0) { sql = sql + " AND"; } sql = sql + " LAST_NAME = " + member.getLastName(); paramCount++; } ResultSet rs = connection.createStatement().executeQuery(sql); if (rs.next()) { toSearchForMember.setFirstName(rs.getString("FIRST_NAME")); toSearchForMember.setLastName(rs.getString("LAST_NAME")); toSearchForMember.setDriverLicense(rs.getBoolean("LICENSE")); toSearchForMember.setId(rs.getLong("ID")); } } catch (SQLException e) { throw new RuntimeException(e); } } return toSearchForMember; }
From source file:com.flexive.core.storage.PostgreSQL.PostgreSQLSequencerStorage.java
/** * {@inheritDoc}//from w w w .j a va 2 s . c om */ @Override public long fetchId(String name, boolean allowRollover) throws FxCreateException { Connection con = null; PreparedStatement ps = null; try { // Obtain a database connection con = Database.getDbConnection(); //TODO: catch exhausted! ps = con.prepareStatement("SELECT NEXTVAL(?)"); ps.setString(1, PG_SEQ_PREFIX + name); ResultSet rs = ps.executeQuery(); if (rs != null && rs.next()) { // System.out.println("==> FETCH FOR " + name+ " => "+rs.getLong(1)); return rs.getLong(1); } else throw new FxCreateException(LOG, "ex.sequencer.fetch.failed", name); } catch (SQLException exc) { throw new FxCreateException(LOG, exc, "ex.sequencer.fetch.failedMsg", name, exc.getMessage()); } finally { Database.closeObjects(PostgreSQLSequencerStorage.class, con, ps); } }
From source file:net.mindengine.oculus.frontend.service.issue.JdbcIssueDAO.java
@Override public void linkTestsToIssue(IssueCollation issueCollation) throws Exception { /*//from w w w. j a va 2s. com * Inserting into issue_collations table first because then we will use * its generated index */ PreparedStatement ps = getConnection() .prepareStatement("insert into issue_collations (issue_id, reason_pattern) values (?,?)"); ps.setLong(1, issueCollation.getIssueId()); ps.setString(2, issueCollation.getReasonPattern()); logger.info(ps); ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { issueCollation.setId(rs.getLong(1)); } else throw new Exception("An error appeared while linking tests to issue"); /* * Inserting all tests into issue_collation_tests table */ for (IssueCollationTest test : issueCollation.getTests()) { update("insert into issue_collation_tests (issue_collation_id, test_id, test_name) values (" + issueCollation.getId() + "," + test.getTestId() + ", :testName)", "testName", test.getTestName()); } update("update issues set dependent_tests = dependent_tests + :size where id = :id", "size", issueCollation.getTests().size(), "id", issueCollation.getIssueId()); /* * Inserting all conditions into issue_collation_conditions table */ for (IssueCollationCondition condition : issueCollation.getConditions()) { update("insert into issue_collation_conditions (issue_collation_id, trm_property_id, value) values (:issueCollationId, :trmPropertyId, :value)", "issueCollationId", issueCollation.getId(), "trmPropertyId", condition.getTrmPropertyId(), "value", condition.getValue()); } }
From source file:com.mobilewallet.common.dao.LoginDAO.java
public User login(String userId) { User user = null;// w w w. ja v a2 s. c o m Connection connection = null; PreparedStatement pstmt = null; ResultSet rs = null; try { connection = dataSource.getConnection(); pstmt = connection.prepareStatement(loginQuery); pstmt.setString(1, userId); rs = pstmt.executeQuery(); if (rs.next()) { user = new User(); user.setUserId(rs.getLong("u_id")); user.setEmail(rs.getString("u_email")); user.setName(rs.getString("u_name")); user.setMyRefCode(rs.getString("u_my_ref_code")); user.setFriendRefCode(rs.getString("u_friend_ref_code")); user.setAmount(rs.getFloat("w_amount")); log.info("Amount In DAO : " + rs.getFloat("w_amount")); } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { } try { if (pstmt != null) { pstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return user; }
From source file:com.l2jfree.gameserver.datatables.TradeListTable.java
private void load(boolean custom) { Connection con = null;/*from w w w .j a va2 s. c o m*/ /* * Initialize Shop buylist */ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement1 = con .prepareStatement("SELECT * FROM " + (custom ? "custom_merchant_shopids" : "merchant_shopids")); ResultSet rset1 = statement1.executeQuery(); while (rset1.next()) { PreparedStatement statement = con.prepareStatement("SELECT * FROM " + (custom ? "custom_merchant_buylists" : "merchant_buylists") + " WHERE shop_id=? ORDER BY " + L2DatabaseFactory.getInstance().safetyString("order") + " ASC"); statement.setInt(1, rset1.getInt("shop_id")); ResultSet rset = statement.executeQuery(); L2TradeList buylist = new L2TradeList(rset1.getInt("shop_id")); buylist.setNpcId(rset1.getString("npc_id")); buylist.setCustom(custom); int _itemId = 0; int _itemCount = 0; int _price = 0; if (!buylist.isGm() && NpcTable.getInstance().getTemplate(rset1.getInt("npc_id")) == null) _log.warn("TradeListTable: Merchant id " + rset1.getString("npc_id") + " with" + (custom ? " custom " : " ") + "buylist " + buylist.getListId() + " not exist."); try { while (rset.next()) { _itemId = rset.getInt("item_id"); _price = rset.getInt("price"); int count = rset.getInt("count"); int currentCount = rset.getInt("currentCount"); int restoreTime = rset.getInt("time"); L2ItemInstance buyItem = ItemTable.getInstance().createDummyItem(_itemId); if (buyItem == null) continue; _itemCount++; if (count > -1) buyItem.setCountDecrease(true); if (_price <= -1) _price = ItemTable.getInstance().getTemplate(_itemId).getReferencePrice(); buyItem.setPriceToSell(_price); buyItem.setRestoreTime(restoreTime); buyItem.setInitCount(count); if (currentCount > -1) buyItem.setCount(currentCount); else buyItem.setCount(count); buylist.addItem(buyItem); if (!buylist.isGm() && buyItem.getReferencePrice() > _price && _price != -1) _log.warn("TradeListTable: Reference price of item " + _itemId + " in" + (custom ? " custom " : " ") + "buylist " + buylist.getListId() + " higher then sell price."); } } catch (Exception e) { _log.warn("TradeListTable: Problem with" + (custom ? " custom " : " ") + "buylist " + buylist.getListId() + " item " + _itemId + "."); } if (_itemCount > 0) { _lists.put(buylist.getListId(), buylist); _nextListId = Math.max(_nextListId, buylist.getListId() + 1); } else _log.warn("TradeListTable: Empty " + (custom ? "custom " : "") + " buylist " + buylist.getListId() + "."); rset.close(); statement.close(); } rset1.close(); statement1.close(); _log.info("TradeListTable: Loaded " + _lists.size() + (custom ? " custom " : " ") + "buylists."); /* * Restore Task for reinitialize count of buy item */ try { int time = 0; long savetimer = 0; long currentMillis = System.currentTimeMillis(); PreparedStatement statement2 = con.prepareStatement("SELECT DISTINCT time, savetimer FROM " + (custom ? "merchant_buylists" : "merchant_buylists") + " WHERE time <> 0 ORDER BY time"); ResultSet rset2 = statement2.executeQuery(); while (rset2.next()) { time = rset2.getInt("time"); savetimer = rset2.getLong("savetimer"); if (savetimer - currentMillis > 0) ThreadPoolManager.getInstance().scheduleGeneral(new RestoreCount(time), savetimer - System.currentTimeMillis()); else ThreadPoolManager.getInstance().scheduleGeneral(new RestoreCount(time), 0); } rset2.close(); statement2.close(); } catch (Exception e) { _log.warn( "TradeListTable:" + (custom ? " custom " : " ") + "could not restore Timer for Item count.", e); } } catch (Exception e) { // problem with initializing buylists, go to next one _log.warn("TradeListTable:" + (custom ? " custom " : " ") + "buylists could not be initialized.", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java
@Override public List<User> listAll() { // Connection conn = getConnection(); final List<User> listUser = new ArrayList<User>(); String sql = "select * from t_user"; getJdbcTemplate().query(sql, new RowCallbackHandler() { @Override//from w w w . j ava 2 s . c o m public void processRow(ResultSet rs) throws SQLException { listUser.clear(); User user = null; while (rs.next()) { user = new User(); user.setId(rs.getLong("f_id")); user.setUsername(rs.getString("f_username")); user.setNickname(rs.getString("f_nickname")); listUser.add(user); } // rs.close(); // , ResultSet ? } }); // try { // Statement state = conn.createStatement(); // ResultSet rs = state.executeQuery(sql); // listUser = new ArrayList<User>(); // User user = null; // while (rs.next()) { // System.out.println(rs.getString(3)); // user = new User(); // user.setId(rs.getLong("f_id")); // user.setUsername(rs.getString("f_username")); // user.setNickname(rs.getString("f_nickname")); // listUser.add(user); // // } // rs.close(); // } catch (SQLException e) { // e.printStackTrace(); // } finally { // try { // conn.close(); // } catch (SQLException e) { // e.printStackTrace(); // } // } return listUser; }
From source file:org.ulyssis.ipp.processor.Processor.java
private Optional<Long> getLastUpdateForReader(Connection connection, int readerId) throws SQLException { String statement = "SELECT \"updateCount\" FROM \"tagSeenEvents\" WHERE \"readerId\" = ? " + "ORDER BY \"updateCount\" DESC FETCH FIRST ROW ONLY"; try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setInt(1, readerId);/*w w w .j a v a2 s . c o m*/ ResultSet rs = stmt.executeQuery(); if (rs.next()) { return Optional.of(rs.getLong("updateCount")); } else { return Optional.empty(); } } }