List of usage examples for java.sql ResultSet TYPE_SCROLL_INSENSITIVE
int TYPE_SCROLL_INSENSITIVE
To view the source code for java.sql ResultSet TYPE_SCROLL_INSENSITIVE.
Click Source Link
ResultSet
object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet
. From source file:no.polaric.aprsdb.MyDBSession.java
/** * Get points that were transmitted via a certain digipeater during a certain time span. *//*from w ww . ja v a 2 s. co m*/ public DbList<TPoint> getPointsVia(String digi, Reference uleft, Reference lright, java.util.Date from, java.util.Date to) throws java.sql.SQLException { _log.debug("MyDbSession", "getPointsVia: " + digi + ", " + df.format(from) + " - " + df.format(to)); PreparedStatement stmt = getCon().prepareStatement( " SELECT DISTINCT position " + " FROM \"AprsPacket\" p, \"PosReport\" r " + " WHERE p.src=r.src " + " AND p.time=r.rtime " + " AND (substring(p.path, '([^,\\*]+).*\\*.*')=? OR " + " (substring(p.ipath, 'qAR,([^,\\*]+).*')=? AND p.path !~ '.*\\*.*')) " + " AND position && ST_MakeEnvelope(?, ?, ?, ?, 4326) " + " AND p.time > ? AND p.time < ? LIMIT 10000", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setString(1, digi); stmt.setString(2, digi); LatLng ul = uleft.toLatLng(); LatLng lr = lright.toLatLng(); stmt.setDouble(3, ul.getLng()); stmt.setDouble(4, ul.getLat()); stmt.setDouble(5, lr.getLng()); stmt.setDouble(6, lr.getLat()); stmt.setTimestamp(7, date2ts(from)); stmt.setTimestamp(8, date2ts(to)); stmt.setMaxRows(10000); return new DbList(stmt.executeQuery(), rs -> { return new TPoint(null, getRef(rs, "position")); }); }
From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsProvider.java
@Override public Outcome handleRequest(Exchange exc) throws Exception { Connection con = dataSource.getConnection(); try {// w w w . j ava 2 s. c o m int offset = URLParamUtil.getIntParam(router.getUriFactory(), exc, "offset"); int max = URLParamUtil.getIntParam(router.getUriFactory(), exc, "max"); int total = getTotal(con); Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet r = s.executeQuery(getOrderedStatistics(router.getUriFactory(), exc)); createJson(exc, r, offset, max, total); } catch (Exception e) { log.warn("Could not retrieve statistics.", e); return Outcome.ABORT; } finally { closeConnection(con); } return Outcome.RETURN; }
From source file:com.wabacus.system.dataset.select.rationaldbassistant.GetDataSetBySQL.java
protected ResultSet executeQuery(String datasource, String sql) throws SQLException { if (Config.show_sql) log.info("Execute sql: " + sql); if (this.isPreparedStmt) { PreparedStatement pstmt = rrequest.getConnection(datasource).prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); if (lstConditions.size() > 0) { AbsDatabaseType dbtype = rrequest.getDbType(datasource); for (int i = 0; i < lstConditions.size(); i++) { if (Config.show_sql) log.info("param" + (i + 1) + "=" + lstConditions.get(i)); lstConditionsTypes.get(i).setPreparedStatementValue(i + 1, lstConditions.get(i), pstmt, dbtype); }//from w w w . j a v a2 s . c om } rrequest.addUsedStatement(pstmt); return pstmt.executeQuery(); } else { Statement stmt = rrequest.getConnection(datasource).createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rrequest.addUsedStatement(stmt); return stmt.executeQuery(sql); } }
From source file:net.xqx.controller.web.QyzzController.java
/** * ?/*from ww w.j a va2 s . com*/ * * @return */ @RequestMapping("/fdckfqy") public String fdckfqy(HttpServletRequest request) { PageDao pageDao = new PageDao(); String pageCount = request.getParameter("pageCount");// ??? if (pageCount == null || "".equals(pageCount)) { pageCount = "1"; } int totalRow = 0;// ? String total = request.getParameter("totalRow"); int totalrow = 0; if (null != total && !"".equals(total)) { totalrow = Integer.parseInt(total); } Page page = null; String companyName = request.getParameter("companyName"); if (companyName != null && !"".equals(companyName)) { companyName = companyName.trim(); } String certificateLevel = request.getParameter("certificateLevel"); request.setAttribute("companyName", companyName); request.setAttribute("certificateLevel", certificateLevel); Connection conn = pageDao.getAptitudeConnection(); PreparedStatement statement = null; ResultSet rs = null; String hql = ""; try { if (companyName != null && !"".equals(companyName) && (certificateLevel == null || "".equals(certificateLevel))) { hql = "select count(*) from TCompanyInfo c left join TCertificate cer " + "on c.fCompanyId=cer.fCompanyId left join TRegInfo r " + "on c.fCompanyId=r.fCompanyInfoId where c.fChecked=1 and c.fCompanyName like " + "'" + "%" + companyName + "%" + "'"; String sql = "select c.fCompanyName,c.fCompanyType,c.fRightMan,r.fCapital,r.fPaiclUpCapital,r.fRegLicenseNo," + "cer.fCertificateLevel,cer.fCertificateNo,c.fOperatingDate,cer.fCertifyDate," + "cer.fValidBeginDate,cer.fValidEndDate,c.fAddress,c.fDetails,c.fCompanyId from TCompanyInfo c left join TCertificate cer " + "on c.fCompanyId=cer.fCompanyId left join TRegInfo r " + "on c.fCompanyId=r.fCompanyInfoId where c.fChecked=1 and c.fCompanyName like ? order by c.fCompanyId desc"; totalRow = pageDao.getAmount(hql);// select count ? if (totalRow != totalrow) { pageCount = "1"; } page = new Page(totalRow, pageCount, 11); statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); statement.setMaxRows(page.getEndIndex()); statement.setString(1, "%" + companyName + "%"); rs = statement.executeQuery(); rs.first(); rs.relative(page.getBeginIndex() - 1); request.setAttribute("totalPage", page.getTotal());// ? request.setAttribute("pageCount", page.getCount());// ?? request.setAttribute("companyName", companyName);// ?? } else if (companyName != null && !"".equals(companyName) && certificateLevel != null && !"".equals(certificateLevel)) { hql = "select count(*) from TCompanyInfo c left join TCertificate cer " + "on c.fCompanyId=cer.fCompanyId left join TRegInfo r " + "on c.fCompanyId=r.fCompanyInfoId where c.fChecked=1 and c.fCompanyName like " + "'" + "%" + companyName + "%" + "'" + " and cer.fCertificateLevel=" + "'" + certificateLevel + "'"; String sql = "select c.fCompanyName,c.fCompanyType,c.fRightMan,r.fCapital,r.fPaiclUpCapital,r.fRegLicenseNo," + "cer.fCertificateLevel,cer.fCertificateNo,c.fOperatingDate,cer.fCertifyDate," + "cer.fValidBeginDate,cer.fValidEndDate,c.fAddress,c.fDetails,c.fCompanyId from TCompanyInfo c left join TCertificate cer " + "on c.fCompanyId=cer.fCompanyId left join TRegInfo r " + "on c.fCompanyId=r.fCompanyInfoId where c.fChecked=1 and c.fCompanyName like ? and cer.fCertificateLevel=? order by c.fCompanyId desc"; totalRow = pageDao.getAmount(hql);// select count ? if (totalRow != totalrow) { pageCount = "1"; } page = new Page(totalRow, pageCount, 11); statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); statement.setMaxRows(page.getEndIndex()); statement.setString(1, "%" + companyName + "%"); statement.setString(2, certificateLevel); rs = statement.executeQuery(); rs.first(); rs.relative(page.getBeginIndex() - 1); request.setAttribute("totalPage", page.getTotal());// ? request.setAttribute("pageCount", page.getCount());// ?? request.setAttribute("companyName", companyName);// ?? request.setAttribute("certificateLevel", certificateLevel);// ?? } TCompanyInfo companyInfo = null; List<TCompanyInfo> companyInfos = new ArrayList<TCompanyInfo>(); if (rs != null) { while (rs.next()) { companyInfo = new TCompanyInfo(); companyInfo.setfCompanyName(rs.getString(1)); companyInfo.setfCompanyType(rs.getString(2)); companyInfo.setfRightMan(rs.getString(3)); companyInfo.setfCapitals(rs.getString(4)); companyInfo.setfCapitalsUp(rs.getString(5)); companyInfo.setfLicenseNo(rs.getString(6)); companyInfo.setfCertificateLevel(rs.getString(7)); companyInfo.setfCertificateNo(rs.getString(8)); companyInfo.setfOperatingDate(rs.getString(9)); companyInfo.setfCertificateDate(rs.getString(10)); companyInfo.setfCertificateBeginDate(rs.getString(11)); companyInfo.setfCertificateEndDate(rs.getString(12)); companyInfo.setfRegAddress(rs.getString(13)); companyInfo.setfDetails(rs.getString(14)); companyInfo.setfCompanyId(rs.getInt(15)); companyInfos.add(companyInfo); } } request.setAttribute("companyInfos", companyInfos); // rs.close(); // statement.close(); // conn.close(); } catch (SQLException e) { System.out.println("!"); e.printStackTrace(); return "web/qycx"; } finally { pageDao.closeConnection(rs, statement, conn); } // Sort hotNewsSort = new Sort(Direction.DESC, "fdjTimes", "ffbTime"); Pageable hotNewsRecPageable = new PageRequest(0, 8, hotNewsSort); List<TNews> hotNewsList = newsDao.getHotNews(hotNewsRecPageable).getContent(); request.setAttribute("hotNewsList", hotNewsList); // ?? Sort recNewsSort = new Sort(Direction.DESC, "fIsRecord", "ffbTime"); Pageable recNewsRecPageable = new PageRequest(0, 8, recNewsSort); List<TNews> recNewsList = newsDao.getNewsRec(recNewsRecPageable).getContent(); request.setAttribute("recNewsList", recNewsList); request.setAttribute("totalRow", totalRow); return "web/qycx"; }
From source file:DbManager.java
/** * Initialize the DbManager.//from ww w .j av a2 s . c om * * @param driver * the driver. * @param database * the database name. * @param login * the login. * @param passwd * the password. * @param stmtsSize * the max number of Statement instances. * @param pstmtsSize * the max number of PreparedStatement instances. * @param rstsSize * the max number of ResultSet instances. */ public void dbManager(String driver, String database, String login, String passwd, int stmtsSize, int pstmtsSize, int rstsSize) { dbArray = true; this.stmtsSize = stmtsSize; this.pstmtsSize = pstmtsSize; this.rstsSize = rstsSize; try { initDb(driver, database, login, passwd); if (stmtsSize > 0) { stmts = new Statement[stmtsSize]; for (int i = 0; i < stmtsSize; i++) { stmts[i] = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); } } if (pstmtsSize > 0) { pstmts = new PreparedStatement[pstmtsSize]; } if (rstsSize != 0) { rsts = new ResultSet[rstsSize]; } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.etudes.jforum.dao.sqlserver.SqlServerPostDAO.java
/** * @see org.etudes.jforum.dao.PostDAO#selectById(int) *///from w ww . j a v a 2s.c om public Post selectById(int postId) throws Exception { PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.selectById"), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); p.setInt(1, postId); ResultSet rs = p.executeQuery(); Post post = new Post(); if (rs.next()) { post = this.makePost(rs); } rs.close(); p.close(); return post; }
From source file:org.nuxeo.storage.file.utils.CheckDocumentFileIsUnique.java
public static boolean isUniqueWithSQL(DocumentModel inDoc) throws SQLException, ClientException { // What do we do with null? if (inDoc == null) { throw new IllegalArgumentException("inDoc should not be null"); }// ww w .j a va2 s .com // Nothing if it's a proxy. It's ok, and not a duplicate if (inDoc.isImmutable() || inDoc.isProxy()) { return true; } // If we have no file, let's consider it's ok if (!inDoc.hasSchema("file")) { return true; } Blob theFile = (Blob) inDoc.getPropertyValue("file:content"); if (theFile == null) { return true; } //_myLog.warn("CHECKCKING UNIQUENESS..."); //OK, now we query Connection co = ConnectionHelper.getConnection(null); try { String statementStr = String.format(kSTATEMENT_SQL, theFile.getDigest(), inDoc.getId()); //_myLog.warn("... with statement:\n" + statementStr); //Statement st = co.createStatement(); Statement st = co.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = st.executeQuery(statementStr); int count = -1; if (rs.first()) { count = rs.getInt(1); } else { throw new SQLException("Could not retrieve the COUNT(*) column"); } //_myLog.warn("CHECKCKING UNIQUENESS, count = " + count + " (0 => unique)"); return count == 0; } catch (SQLException e) { _myLog.warn("CHECKCKING UNIQUENESS, SQLException " + e); throw e; } finally { if (co != null) { co.close(); } } }
From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java
CassandraStatement(CassandraConnection con, String cql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { this.connection = con; this.cql = cql; this.batchQueries = Lists.newArrayList(); this.consistencyLevel = con.defaultConsistencyLevel; if (!(resultSetType == ResultSet.TYPE_FORWARD_ONLY || resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE || resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)) throw new SQLSyntaxErrorException(BAD_TYPE_RSET); this.resultSetType = resultSetType; if (!(resultSetConcurrency == ResultSet.CONCUR_READ_ONLY || resultSetConcurrency == ResultSet.CONCUR_UPDATABLE)) throw new SQLSyntaxErrorException(BAD_TYPE_RSET); this.resultSetConcurrency = resultSetConcurrency; if (!(resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT || resultSetHoldability == ResultSet.CLOSE_CURSORS_AT_COMMIT)) throw new SQLSyntaxErrorException(BAD_HOLD_RSET); this.resultSetHoldability = resultSetHoldability; }
From source file:com.itemanalysis.jmetrik.stats.descriptives.DescriptiveAnalysis.java
public void summarize() throws SQLException { Statement stmt = null;/*from w ww . jav a 2s . c o m*/ ResultSet rs = null; DescriptiveStatistics temp = null; Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); for (VariableAttributes v : variables) { select.addColumn(sqlTable, v.getName().nameForDatabase()); } stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); double value = Double.NaN; while (rs.next()) { for (VariableAttributes v : variables) { temp = data.get(v); if (temp == null) { temp = new DescriptiveStatistics(); data.put(v, temp); } //only increment for non null doubles value = rs.getDouble(v.getName().nameForDatabase()); if (!rs.wasNull()) { temp.addValue(value); } } updateProgress(); } rs.close(); stmt.close(); for (VariableAttributes v : data.keySet()) { publishTable(v); } }