List of usage examples for java.sql ResultSet CONCUR_READ_ONLY
int CONCUR_READ_ONLY
To view the source code for java.sql ResultSet CONCUR_READ_ONLY.
Click Source Link
ResultSet
object that may NOT be updated. From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AccessFrequencyTable.java
public MSSBamAccessFrequencyBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "readAllBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from w ww .j a va 2 s . co m*/ try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectAccessFrequencyBuff + "ORDER BY " + "afrq.Id ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamAccessFrequencyBuff> buffList = new ArrayList<MSSBamAccessFrequencyBuff>(); while (resultSet.next()) { MSSBamAccessFrequencyBuff buff = unpackAccessFrequencyResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamAccessFrequencyBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:org.ala.lucene.ExternalIndexLoader.java
/** * Loads collections and institutions into the BIE search index. * // ww w . jav a2 s . c o m * @throws Exception */ public void loadInstitutions() throws Exception { logger.info("Starting syncing institution information...."); Connection conn = collectoryDataSource.getConnection(); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery( "select uid, guid, name, acronym, institution_type, pub_description from institution"); SolrServer solrServer = solrUtils.getSolrServer(); solrServer.deleteByQuery("idxtype:" + IndexedTypes.INSTITUTION); // delete institutions! while (rs.next()) { String uid = rs.getString("uid"); String externalGuid = rs.getString("guid"); String name = rs.getString("name"); String acronym = rs.getString("acronym"); String institutionType = rs.getString("institution_type"); // university/museum/government String pubDescription = rs.getString("pub_description"); SolrInputDocument doc = new SolrInputDocument(); doc.addField("acronym", acronym, 1.2f); doc.addField("name", name, 1.2f); doc.addField("guid", baseUrlForCollectory + uid); if (externalGuid != null) { doc.addField("otherGuid", externalGuid); } doc.addField("text", pubDescription); doc.addField("url", baseUrlForCollectory + uid); doc.addField("id", baseUrlForCollectory + uid); doc.addField("idxtype", IndexedTypes.INSTITUTION); doc.addField("institutionType", institutionType); // doc.addField("aus_s", "yes"); doc.addField("australian_s", "recorded"); // so they appear in default QF search solrServer.add(doc); } solrServer.commit(); rs.close(); stmt.close(); conn.close(); logger.info("Finished syncing institution information."); }
From source file:io.cloudslang.content.database.utils.SQLInputsUtilsTest.java
@Test public void getResultSetConcurrencySimple() throws Exception { assertEquals(ResultSet.CONCUR_READ_ONLY, getResultSetConcurrency(CONCUR_READ_ONLY)); assertEquals(ResultSet.CONCUR_UPDATABLE, getResultSetConcurrency(CONCUR_UPDATABLE)); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java
public MSSBamBaseDomainBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "readDerived()"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }// ww w . ja v a 2 s . c o m MSSBamBaseDomainBuff buff; long Id = PKey.getRequiredId(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE " + "bdm.Id = " + Long.toString(Id) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); if (resultSet.next()) { classCode = resultSet.getString(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected"); } } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (classCode.equals("BDM")) { buff = readBuff(Authorization, PKey); } else if (classCode.equals("DOM")) { buff = schema.getTableDomain().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("LENT")) { buff = schema.getTableLegalEntity().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("COM")) { buff = schema.getTableCompany().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("USR")) { buff = schema.getTableUser().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("PRJ")) { buff = schema.getTableProject().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("VER")) { buff = schema.getTableVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("MJV")) { buff = schema.getTableMajorVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("MNV")) { buff = schema.getTableMinorVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else if (classCode.equals("TLD")) { buff = schema.getTableTLD().readBuffByIdIdx(Authorization, PKey.getRequiredId()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } return (buff); }
From source file:com.tera.common.database.query.CQueryService.java
@Override public int[] getUsedIds(String query, String idColumn) { PreparedStatement statement = prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = null;/*from w w w. j ava 2s. co m*/ try { resultSet = statement.executeQuery(); resultSet.last(); int count = resultSet.getRow(); resultSet.beforeFirst(); int[] ids = new int[count]; for (int i = 0; i < count; i++) { resultSet.next(); ids[i] = resultSet.getInt(idColumn); } return ids; } catch (SQLException e) { log.error("Can't get id's using query {}", query, e); } finally { close(resultSet, statement); } return new int[0]; }
From source file:edu.ku.brc.specify.conversion.IdHashMapper.java
/** * Maps the first index to the second index. * The SQL to do the mappings.//from ww w . j a v a2 s.c om */ public void mapAllIds() { if (sql == null) { throw new RuntimeException("Calling mapAllIds and the SQL statement is NULL!"); } int mappingCount = getMapCount(mapTableName); wasEmpty = mappingCount == 0; if (doDelete || mappingCount == 0) { if (!isUsingSQL) { BasicSQLUtils.deleteAllRecordsFromTable(oldConn, mapTableName, BasicSQLUtils.myDestinationServerType); } if (frame != null) { frame.setDesc("Mapping " + mapTableName); } try { if (frame != null) { frame.setProcess(0, 0); } PreparedStatement pStmt = oldConn.prepareStatement("INSERT INTO " + mapTableName + " VALUES (?,?)"); Statement stmtOld = oldConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmtOld.executeQuery(sql); if (rs.last()) { if (frame != null) { frame.setProcess(0, rs.getRow()); } } if (rs.first()) { int count = 0; do { pStmt.setInt(1, rs.getInt(1)); // Old Index pStmt.setInt(2, rs.getInt(2)); // New Index if (pStmt.executeUpdate() != 1) { String msg = String.format("Error writing to Map table[%s] old: %d new: %d", mapTableName, rs.getInt(1), rs.getInt(2)); log.error(msg); throw new RuntimeException(msg); } if (frame != null) { if (count % 1000 == 0) { frame.setProcess(count); } } else { if (count % 2000 == 0) { log.debug("Mapped " + count + " records from " + tableName); } } count++; } while (rs.next()); log.info("Mapped " + count + " records from " + tableName); if (frame != null) { frame.setProcess(0, 0); } } else { log.info("No records to map in " + tableName); } rs.close(); stmtOld.close(); pStmt.close(); } catch (SQLException ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(IdHashMapper.class, ex); log.error("trying to execute:" + sql); log.error(ex); throw new RuntimeException(ex); } } else { log.debug("Skipping the build of mapper: " + mapTableName); } if (frame != null) { frame.setProcess(0, 0); } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.VerifyCollectionDlg.java
/** * // w w w . j a va2 s . co m */ private void processResults() { //loadAndPushResourceBundle("stats"); RelationshipType paleoRelType = isCollectionPaleo ? ExportPaleo.discoverPaleRelationshipType() : RelationshipType.eTypeError; boolean hasCritical = false; UIRegistry.setDoShowAllResStrErors(false); //logMsg("Verifying the Collection..."); File tmpFile = ipadExporter.getConfigFile(VERIFY_XML); if (tmpFile != null && tmpFile.exists()) { Statement stmt0 = null; try { Element root = XMLHelper.readFileToDOM4J(tmpFile); if (root != null) { ArrayList<String> okMsgs = new ArrayList<String>(); ArrayList<String> warnMsgs = new ArrayList<String>(); ArrayList<String> criticalMsgs = new ArrayList<String>(); int issueCnt = 0; String mainFont = "<font face='verdana' color='black'>"; String headHTML = "<htmL><head></head><body bgcolor='#EEEEEE'>" + mainFont; StringBuilder sb = new StringBuilder(headHTML); htmlPane.setText(sb.toString() + "<BR><BR>Verifying collection...</font></body></html>"); List<?> items = root.selectNodes("eval"); //$NON-NLS-1$ stmt0 = DBConnection.getInstance().getConnection() .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt0.setFetchSize(Integer.MIN_VALUE); for (Iterator<?> capIter = items.iterator(); capIter.hasNext();) { Element fieldNode = (Element) capIter.next(); //String name = fieldNode.attributeValue("name"); //$NON-NLS-1$ String desc = fieldNode.attributeValue("desc"); //$NON-NLS-1$ String sql = fieldNode.getTextTrim(); String cond = fieldNode.attributeValue("cond"); String vStr = fieldNode.attributeValue("val"); String isFmt = fieldNode.attributeValue("fmt"); String stop = fieldNode.attributeValue("stop"); boolean doStop = stop != null && stop.equals("true"); String display = fieldNode.attributeValue("display"); boolean doDsp = display == null || display.equals("true"); String paleo = fieldNode.attributeValue("isPaleo"); boolean isPaleo = paleo != null && paleo.equals("true"); if (isPaleo && !isCollectionPaleo) continue; String paleoTypeStr = fieldNode.attributeValue("paleotype"); //$NON-NLS-1$ if (isCollectionPaleo && StringUtils.isNotEmpty(paleoTypeStr)) { if (paleoRelType != paleoLookupHash.get(paleoTypeStr)) { continue; } } sql = ipadExporter.adjustSQL(sql); Object rv = BasicSQLUtils.querySingleObj(sql); Integer retVal = cnvToInt(rv); boolean isError = false; if (retVal != null && StringUtils.isNotEmpty(cond) && StringUtils.isNotEmpty(vStr)) { Integer value = cnvToInt(vStr); if (value != null) { if (cond.equals(">")) { isError = retVal.intValue() > value.intValue(); } else if (cond.equals("=")) { isError = retVal.intValue() == value.intValue(); } else if (cond.equals("<")) { isError = retVal.intValue() < value.intValue(); } } } /* String fontSt = isError ? "<font color='"+(doStop ? "red" : "orange")+"'>" : ""; String fontEn = isError ? "</font>" : ""; if (StringUtils.isNotEmpty(isFmt) && isFmt.equalsIgnoreCase("true")) { sb.append(String.format("<LI>%s%s%s</LI>", fontSt, String.format(desc, retVal), fontEn)); issueCnt++; } else { sb.append(String.format("<LI>%s%s%s</LI>", fontSt, desc, fontEn)); issueCnt++; } */ String fullMsg; if (StringUtils.isNotEmpty(isFmt) && isFmt.equalsIgnoreCase("true")) { fullMsg = String.format(desc, retVal); } else { fullMsg = desc; } if (isError) { if (doStop) { criticalMsgs.add(fullMsg); hasCritical = true; } else { warnMsgs.add(fullMsg); } } else if (doDsp) { okMsgs.add(fullMsg); } issueCnt++; //worker.firePropertyChange(PROGRESS, 0, cnt); } stmt0.close(); sb = new StringBuilder(headHTML); if (issueCnt == 0) { sb.append("<BR><BR>There were no issues to report."); } else { listMsgs(sb, "Passed", okMsgs, "green", true); listMsgs(sb, "Warnings", warnMsgs, "yellow", true); listMsgs(sb, "Critical Errors - Cannot proceed.", criticalMsgs, "red", true); } sb.append(mainFont + "<BR>Verification Complete.<BR><BR></font></body></html>"); htmlPane.setText(sb.toString()); // For external report sb = new StringBuilder("<htmL><head><title>Collection Verification</title></head><body>"); listMsgs(sb, "Passed", okMsgs, "green", false); listMsgs(sb, "Warnings", warnMsgs, "yellow", false); listMsgs(sb, "Critical Errors - Cannot proceed.", criticalMsgs, "red", false); sb.append("</body></html>"); try { TableWriter tblWriter = new TableWriter(reportPath, "Collection Verification Report", true); tblWriter.println(sb.toString()); tblWriter.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (stmt0 != null) stmt0.close(); } catch (Exception ex) { } } } okBtn.setEnabled(!hasCritical); }
From source file:architecture.ee.jdbc.util.impl.JdbcHelperImpl.java
public PreparedStatement createScrollablePreparedStatement(Connection con, String sql) throws SQLException { if (isScrollResultsSupported()) return con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); else//from ww w.j ava 2s .c om return con.prepareStatement(sql); }
From source file:GuestBookServlet.java
private void printComments(PrintWriter out, Locale loc) throws IOException { Connection conn = null;/*from w w w.ja v a2s . c o m*/ try { DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, loc); ResultSet results; Statement stmt; int rows, count; conn = DriverManager.getConnection(jdbcURL, connectionProperties); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); results = stmt.executeQuery("SELECT NAME, EMAIL, CMT_DATE, " + "COMMENT, COMMENT_ID " + "FROM COMMENT " + "ORDER BY CMT_DATE"); out.println("<dl>"); results.last(); results.next(); rows = results.getRow(); // pick a random row rows = random.nextInt() % rows; if (rows < 4) { // if the random row is less than 4, print the first 4 rows results.afterLast(); } else { // otherwise go to the specified row, print the prior 5 rows results.absolute(rows); } count = 0; // print up to 5 rows going backwards from the randomly // selected row while (results.previous() && (count < 5)) { String name, email, cmt; Date date; count++; name = results.getString(1); if (results.wasNull()) { name = "Unknown User"; } email = results.getString(2); if (results.wasNull()) { email = "user@host"; } date = results.getDate(3); if (results.wasNull()) { date = new Date((new java.util.Date()).getTime()); } cmt = results.getString(4); if (results.wasNull()) { cmt = "No comment."; } out.println("<dt><b>" + name + "</b> (" + email + ") on " + fmt.format(date) + "</dt>"); cmt = noXML(cmt); out.println("<dd> " + cmt + "</dd>"); } out.println("</dl>"); } catch (SQLException e) { out.println("A database error occurred: " + e.getMessage()); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AttachmentTable.java
public MSSBamAttachmentBuff readBuff(MSSBamAuthorization Authorization, MSSBamAttachmentPKey PKey) { final String S_ProcName = "readBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }// w w w . j av a 2 s.c o m try { Connection cnx = schema.getCnx(); long AttachmentId = PKey.getRequiredAttachmentId(); String sql = S_sqlSelectAttachmentBuff + "WHERE " + "attc.AttachmentId = " + Long.toString(AttachmentId) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); if (resultSet.next()) { MSSBamAttachmentBuff buff = unpackAttachmentResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }