List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:com.tascape.reactor.report.MySqlBaseBean.java
public List<Map<String, Object>> getSuiteResultDetailHistory(long startTime, long stopTime, int numberOfEntries, String suiteName, boolean invisibleIncluded) throws NamingException, SQLException { String sr = "SELECT " + SuiteResult.SUITE_RESULT_ID + " FROM " + SuiteResult.TABLE_NAME + " WHERE " + SuiteResult.START_TIME + " > ?" + " AND " + SuiteResult.STOP_TIME + " < ?" + " AND " + SuiteResult.SUITE_NAME + " = ?"; if (!invisibleIncluded) { sr += " AND NOT " + SuiteResult.INVISIBLE_ENTRY; }//w ww. ja v a 2 s .c o m sr += " ORDER BY " + SuiteResult.START_TIME + " DESC;"; String tr = "SELECT * FROM " + CaseResult.TABLE_NAME + " WHERE " + CaseResult.EXECUTION_RESULT + " IN (" + sr + ")" + " ORDER BY " + SuiteResult.START_TIME + " DESC;"; try (Connection conn = this.getConnection()) { PreparedStatement stmt = conn.prepareStatement(tr); stmt.setLong(1, startTime); stmt.setLong(2, stopTime); if (suiteName != null && !suiteName.isEmpty()) { stmt.setString(3, suiteName); } LOG.trace("{}", stmt); stmt.setMaxRows(numberOfEntries); ResultSet rs = stmt.executeQuery(); return this.dumpResultSetToList(rs); } }
From source file:de.ingrid.importer.udk.strategy.v1.IDCStrategy1_0_4_fixInspireThemes.java
/** Remove INSPIRE theme from object via "searchterm_obj". */ private void removeInspireThemeFromObject(int themeIdToRemove, long objectId, HashMap<Integer, Long> themeIdToSearchtermId, PreparedStatement psRemoveTermObj, Set<Integer> currThemeIds, String objUuidForLog, String workStateForLog) throws Exception { Long searchtermId = themeIdToSearchtermId.get(themeIdToRemove); // remove only, if term exists if (searchtermId != null) { int cnt = 1; psRemoveTermObj.setLong(cnt++, objectId); // searchterm_obj.obj_id psRemoveTermObj.setLong(cnt++, searchtermId); // searchterm_obj.searchterm_id psRemoveTermObj.executeUpdate(); // also update our set ! currThemeIds.remove(themeIdToRemove); if (log.isDebugEnabled()) { String inspireTheme = UtilsInspireThemes.inspireThemes_de.get(themeIdToRemove); String msg = "Removed INSPIRE Theme: '" + inspireTheme + "'"; msg = msg + ", Obj-UUUID: " + objUuidForLog + ", workState: '" + workStateForLog + "'"; log.debug(msg);/*from w ww .jav a 2 s.c om*/ } } }
From source file:com.jagornet.dhcp.db.JdbcIaManager.java
/** * Delete expired ia.//from w ww . ja v a 2 s. c om * * @param id the id */ protected void deleteExpiredIA(final Long id) { getJdbcTemplate().update( "delete from identityassoc" + " where id=?" + " and not exists (select 1 from iaaddress" + " where identityassoc_id=identityassoc.id" + " and validendtime is not null and validendtime>=?)", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setLong(1, id); java.sql.Timestamp now = new java.sql.Timestamp((new Date()).getTime()); ps.setTimestamp(2, now, Util.GMT_CALENDAR); } }); }
From source file:net.sf.l2j.gameserver.handler.AutoAnnouncementHandler.java
public AutoAnnouncementInstance registerAnnouncment(String announcementTexts, long announcementDelay) { int nextId = nextAutoAnnouncmentId(); java.sql.Connection con = null; try {//from ww w . j a v a 2 s. c o m con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("INSERT INTO auto_announcements (id,announcement,delay) " + "VALUES (?,?,?)"); statement.setInt(1, nextId); statement.setString(2, announcementTexts); statement.setLong(3, announcementDelay); statement.executeUpdate(); statement.close(); } catch (Exception e) { _log.fatal("System: Could Not Insert Auto Announcment into DataBase: Reason: " + "Duplicate Id"); } finally { try { con.close(); } catch (Exception e) { } } return registerAnnouncement(nextId, announcementTexts, announcementDelay); }
From source file:org.killbill.bus.TestPersistentBusDemo.java
@Test(groups = "slow") public void testDemo() throws SQLException, PersistentBus.EventBusException { // Create a Handler (with @Subscribe method) final DummyHandler handler = new DummyHandler(); bus.register(handler);//from ww w . j ava 2 s . c o m // Extract connection from dataSource final Connection connection = dataSource.getConnection(); final DummyEvent event = new DummyEvent("foo", 1L, 2L, UUID.randomUUID()); PreparedStatement stmt = null; try { // In one transaction we both insert a dummy value in some table, and post the event (using same connection/transaction) connection.setAutoCommit(false); stmt = connection.prepareStatement("insert into dummy (dkey, dvalue) values (?, ?)"); stmt.setString(1, "Great!"); stmt.setLong(2, 47L); stmt.executeUpdate(); bus.postFromTransaction(event, connection); connection.commit(); } finally { if (stmt != null) { stmt.close(); } if (connection != null) { connection.close(); } } // // Verify we see the dummy value inserted and also received the event posted // final Connection connection2 = dataSource.getConnection(); PreparedStatement stmt2 = null; try { stmt2 = connection2.prepareStatement("select * from dummy where dkey = ?"); stmt2.setString(1, "Great!"); final ResultSet rs2 = stmt2.executeQuery(); int found = 0; while (rs2.next()) { found++; } Assert.assertEquals(found, 1); } finally { stmt2.close(); } if (connection2 != null) { connection2.close(); } Assert.assertTrue(handler.waitForCompletion(1, 3000)); }
From source file:com.l2jfree.gameserver.model.entity.Couple.java
public Couple(L2Player player1, L2Player player2) { int _tempPlayer1Id = player1.getObjectId(); int _tempPlayer2Id = player2.getObjectId(); _player1Id = _tempPlayer1Id;//w w w. j a va 2s . com _player2Id = _tempPlayer2Id; _affiancedDate = System.currentTimeMillis(); _weddingDate = System.currentTimeMillis(); Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; _id = IdFactory.getInstance().getNextId(); statement = con.prepareStatement( "INSERT INTO couples (id, player1Id, player2Id, maried, affiancedDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)"); statement.setInt(1, _id); statement.setInt(2, _player1Id); statement.setInt(3, _player2Id); statement.setBoolean(4, false); statement.setLong(5, _affiancedDate); statement.setLong(6, _weddingDate); statement.execute(); statement.close(); } catch (Exception e) { _log.error("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.tascape.reactor.report.MySqlBaseBean.java
public List<Map<String, Object>> getSuitesResult(String project, long startTime, long stopTime, int numberOfEntries, String suiteName, String jobName, boolean invisibleIncluded) throws NamingException, SQLException { String sql = "SELECT * FROM " + SuiteResult.TABLE_NAME + " WHERE (" + SuiteResult.START_TIME + " > ?)" + " AND (" + SuiteResult.STOP_TIME + " < ?)"; if (StringUtils.isNotBlank(suiteName)) { sql += " AND (" + SuiteResult.SUITE_NAME + " = ?)"; } else if (StringUtils.isNotBlank(jobName)) { sql += " AND (" + SuiteResult.JOB_NAME + " = ?)"; }/*from w w w .ja v a 2s . c o m*/ if (StringUtils.isNotBlank(project)) { sql += " AND (" + SuiteResult.PROJECT_NAME + " LIKE ?)"; } if (!invisibleIncluded) { sql += " AND NOT " + SuiteResult.INVISIBLE_ENTRY; } sql += " ORDER BY " + SuiteResult.START_TIME + " DESC;"; try (Connection conn = this.getConnection()) { PreparedStatement stmt = conn.prepareStatement(sql); stmt.setLong(1, startTime); stmt.setLong(2, stopTime); if (StringUtils.isNotBlank(suiteName)) { stmt.setString(3, suiteName); } else if (StringUtils.isNotBlank(jobName)) { stmt.setString(3, jobName); } if (StringUtils.isNotBlank(project)) { if (StringUtils.isNotBlank(suiteName) || StringUtils.isNotBlank(jobName)) { stmt.setString(4, project + "%"); } else { stmt.setString(3, project + "%"); } } LOG.trace("{}", stmt); stmt.setMaxRows(numberOfEntries); ResultSet rs = stmt.executeQuery(); return this.dumpResultSetToList(rs); } }
From source file:net.sf.l2j.gameserver.model.entity.Couple.java
public Couple(L2PcInstance player1, L2PcInstance player2) { int _tempPlayer1Id = player1.getObjectId(); int _tempPlayer2Id = player2.getObjectId(); _player1Id = _tempPlayer1Id;//from w ww.ja va2 s . c om _player2Id = _tempPlayer2Id; _affiancedDate = Calendar.getInstance(); _affiancedDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis()); _weddingDate = Calendar.getInstance(); _weddingDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis()); java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement; _Id = IdFactory.getInstance().getNextId(); statement = con.prepareStatement( "INSERT INTO couples (id, player1Id, player2Id, maried, affiancedDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)"); statement.setInt(1, _Id); statement.setInt(2, _player1Id); statement.setInt(3, _player2Id); statement.setBoolean(4, false); statement.setLong(5, _affiancedDate.getTimeInMillis()); statement.setLong(6, _weddingDate.getTimeInMillis()); statement.execute(); statement.close(); } catch (Exception e) { _log.error("", e); } finally { try { con.close(); } catch (Exception e) { } } }
From source file:dk.netarkivet.harvester.datamodel.extendedfield.ExtendedFieldValueDBDAO.java
/** * Read the ExtendedFieldValue with the given extendedFieldID. * @param connection an open connection to the HarvestDatabase * @param aExtendedFieldID A given ID for a ExtendedFieldValue * @param aInstanceID A given instanceID * @return the ExtendedFieldValue with the given extendedFieldID. */// w w w. j a v a2s .com private synchronized ExtendedFieldValue read(Connection connection, Long aExtendedFieldID, Long aInstanceID) { ExtendedFieldValue extendedFieldValue = null; PreparedStatement statement = null; try { statement = connection.prepareStatement( "" + "SELECT extendedfieldvalue_id, " + " extendedfield_id, " + " content " + "FROM extendedfieldvalue " + "WHERE extendedfield_id = ? and instance_id = ?"); statement.setLong(1, aExtendedFieldID); statement.setLong(2, aInstanceID); ResultSet result = statement.executeQuery(); if (!result.next()) { return null; } long extendedfieldvalueId = result.getLong(1); long extendedfieldId = result.getLong(2); long instanceId = aInstanceID; String content = result.getString(3); extendedFieldValue = new ExtendedFieldValue(extendedfieldvalueId, extendedfieldId, instanceId, content); return extendedFieldValue; } catch (SQLException e) { String message = "SQL error reading extended Field " + aExtendedFieldID + " in database" + "\n" + ExceptionUtils.getSQLExceptionCause(e); log.warn(message, e); throw new IOFailure(message, e); } }
From source file:com.tascape.qa.th.db.H2Handler.java
@Override public boolean queueTestSuite(TestSuite suite, String execId) throws SQLException { LOG.info("Queueing test suite result with execution id {} ", execId); final String sql = "INSERT INTO " + SuiteResult.TABLE_NAME + " (" + SuiteResult.SUITE_RESULT_ID + ", " + SuiteResult.SUITE_NAME + ", " + SuiteResult.JOB_NAME + ", " + SuiteResult.JOB_BUILD_NUMBER + ", " + SuiteResult.JOB_BUILD_URL + ", " + SuiteResult.START_TIME + ", " + SuiteResult.STOP_TIME + ", " + SuiteResult.EXECUTION_RESULT + ", " + SuiteResult.NUMBER_OF_TESTS + ", " + SuiteResult.NUMBER_OF_FAILURE + ", " + SuiteResult.PRODUCT_UNDER_TEST + ") VALUES (?,?,?,?,?,?,?,?,?,?,?);"; try (Connection conn = this.getConnection()) { PreparedStatement stmt = conn.prepareStatement(sql); Long time = System.currentTimeMillis(); stmt.setString(1, execId);/*from www. j a v a 2s .com*/ stmt.setString(2, ""); stmt.setString(3, SYS_CONFIG.getJobName()); stmt.setInt(4, SYS_CONFIG.getJobBuildNumber()); stmt.setString(5, SYS_CONFIG.getJobBuildUrl()); stmt.setLong(6, time); stmt.setLong(7, time + 11); stmt.setString(8, ExecutionResult.QUEUED.name()); stmt.setInt(9, suite.getTests().size()); stmt.setInt(10, suite.getTests().size()); stmt.setString(11, SYS_CONFIG.getProdUnderTest()); LOG.debug("{}", stmt); int i = stmt.executeUpdate(); return i == 1; } }