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:edu.ku.brc.specify.conversion.MSULichensFixer.java
private void convertTaxonRecords() { IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); txMapper = IdMapperMgr.getInstance().addTableMapper("taxonname", "TaxonNameID", false); txTypMapper = IdMapperMgr.getInstance().addTableMapper("TaxonomyType", "TaxonomyTypeID", false); txUnitTypMapper = IdMapperMgr.getInstance().addTableMapper("TaxonomicUnitType", "TaxonomicUnitTypeID", false);/*from w w w . j av a 2 s . c o m*/ mappers = new IdMapperIFace[] { txMapper, txMapper, txTypMapper, txMapper, txUnitTypMapper }; newToOldColMap.put("TaxonID", "TaxonNameID"); newToOldColMap.put("ParentID", "ParentTaxonNameID"); newToOldColMap.put("TaxonTreeDefID", "TaxonomyTypeID"); newToOldColMap.put("TaxonTreeDefItemID", "TaxonomicUnitTypeID"); newToOldColMap.put("Name", "TaxonName"); newToOldColMap.put("FullName", "FullTaxonName"); newToOldColMap.put("IsAccepted", "Accepted"); oldToNewColMap.put("TaxonNameID", "TaxonID"); oldToNewColMap.put("ParentTaxonNameID", "ParentID"); oldToNewColMap.put("TaxonomyTypeID", "TaxonTreeDefID"); oldToNewColMap.put("TaxonomicUnitTypeID", "TaxonTreeDefItemID"); oldToNewColMap.put("TaxonName", "Name"); oldToNewColMap.put("FullTaxonName", "FullName"); oldToNewColMap.put("Accepted", "IsAccepted"); BasicSQLUtils.setDBConnection(newDBConn); StringBuilder newSB = new StringBuilder(); StringBuilder vl = new StringBuilder(); for (int i = 0; i < cols.length; i++) { fieldToColHash.put(cols[i], i + 1); colToFieldHash.put(i + 1, cols[i]); if (newSB.length() > 0) newSB.append(", "); newSB.append(cols[i]); if (vl.length() > 0) vl.append(','); vl.append('?'); } StringBuilder oldSB = new StringBuilder(); for (int i = 0; i < oldCols.length; i++) { oldFieldToColHash.put(oldCols[i], i + 1); if (oldSB.length() > 0) oldSB.append(", "); oldSB.append("ttx."); oldSB.append(oldCols[i]); } rankIdOldDBInx = oldFieldToColHash.get("RankID"); String sqlStr = String.format("SELECT %s FROM taxon ", newSB.toString()); log.debug(sqlStr); String fromClause = " FROM taxonname ttx LEFT JOIN msu_lichens.taxonname_TaxonNameID ON OldID = ttx.TaxonNameID LEFT JOIN msu_lichens_6.taxon AS ntx ON NewID = ntx.TaxonID WHERE ntx.TaxonID IS NULL"; String sql = String.format("SELECT %s %s", oldSB.toString(), fromClause); log.debug(sql); String cntSQL = String.format("SELECT COUNT(*) %s", fromClause); log.debug(cntSQL); int txCnt = BasicSQLUtils.getCountAsInt(oldDBConn, cntSQL); if (frame != null) { frame.setProcess(0, txCnt); } log.debug(txCnt); String pStr = String.format("INSERT INTO taxon (%s) VALUES (%s)", newSB.toString(), vl.toString()); log.debug(pStr); try { stmtTx = newDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs1 = stmtTx.executeQuery(sqlStr); ResultSetMetaData rsmd1 = rs1.getMetaData(); colTypes = new int[rsmd1.getColumnCount()]; colSizes = new int[rsmd1.getColumnCount()]; for (int i = 0; i < colTypes.length; i++) { colTypes[i] = rsmd1.getColumnType(i + 1); colSizes[i] = rsmd1.getPrecision(i + 1); } rs1.close(); stmtTx.close(); missingParentTaxonCount = 0; lastEditedByInx = oldFieldToColHash.get("LastEditedBy"); modifiedByAgentInx = fieldToColHash.get("ModifiedByAgentID"); stmtTx = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); pStmtTx = newDBConn.prepareStatement(pStr); int cnt = 0; ResultSet rs = stmtTx.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { processRow(rs, rsmd, null); cnt++; if (cnt % 1000 == 0) { log.debug(cnt); if (frame != null) { frame.setProcess(cnt); } } } rs.close(); if (frame != null) { frame.setProcess(txCnt, txCnt); } String msg = String.format("Stranded Taxon (no parent): %d", missingParentTaxonCount); tblWriter.log(msg); log.debug(msg); if (missingParentTaxonCount > 0) { if (frame != null) frame.setDesc("Renumbering the tree nodes, this may take a while..."); HashSet<Integer> ttdHash = new HashSet<Integer>(); for (CollectionInfo colInfo : CollectionInfo.getFilteredCollectionInfoList()) { if (!ttdHash.contains(colInfo.getTaxonTreeDef().getId())) { DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); TaxonTreeDef taxonTreeDef = colInfo.getTaxonTreeDef(); taxonTreeDef = (TaxonTreeDef) session .getData("FROM TaxonTreeDef WHERE id = " + taxonTreeDef.getId()); sql = "SELECT TaxonID FROM taxon WHERE RankID = 0 AND TaxonTreeDefID = " + taxonTreeDef.getId(); log.debug(sql); Integer txRootId = BasicSQLUtils.getCount(sql); Taxon txRoot = (Taxon) session.getData("FROM Taxon WHERE id = " + txRootId); NodeNumberer<Taxon, TaxonTreeDef, TaxonTreeDefItem> nodeNumberer = new NodeNumberer<Taxon, TaxonTreeDef, TaxonTreeDefItem>( txRoot.getDefinition()); nodeNumberer.doInBackground(); } catch (Exception ex) { //session.rollback(); ex.printStackTrace(); } finally { if (session != null) { session.close(); } } ttdHash.add(colInfo.getTaxonTreeDef().getId()); } } if (frame != null) frame.setDesc("Renumbering done."); } missingParentTaxonCount = 0; } catch (SQLException ex) { ex.printStackTrace(); } finally { try { stmtTx.close(); pStmtTx.close(); } catch (Exception ex) { } } System.out.println("Done."); }
From source file:edu.ku.brc.specify.toycode.BuildSearchIndex.java
/** * // w w w. java2 s. c o m */ public void index() { // 0 1 2 3 4 5 6 7 // CatalogNumber, CountAmt, StartDate, StationFieldNumber TypeStatusName, FullName, Name, RankID, // 8 9 10 11 12 13 14 15 16 17 18 19 // Latitude1, Longitude1, LocalityName, MaxElevation, MinElevation, FullName, Name, RankID, LastName, FirstName, MiddleInitial, Text1 // 20 21 22 23 24 25 26 27 28 //collectionObjectId, DeterminationID, TaxonID, CollectingEventID, LocalityID, GeographyID, AgentID, tx.ParentID, geo.ParentID // 0 1 2 3 4 5 6 7 8 9 10 11 // CatalogNumber, StartDate, StationFieldNumber TypeStatusName, tx.FullName, Latitude1, Longitude1, LocalityName, geo.FullName, LastName, FirstName, MiddleInitial // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 20 1 2 3 4 5 6 7 8 int[] colToTblId = { 1, 1, 10, 10, 4, 4, 4, 4, 2, 2, 2, 2, 2, 3, 3, 3, 5, 5, 5, 1, 1, 9, 4, 10, 2, 3, 5, 4, 3 }; int[] includeCol = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Index for ResultSet (which is one more than the array index) int idIndex = 20; int taxIndex = 23; int geoIndex = 26; int ceIndex = 24; int geoNameIndex = 15; int taxNameIndex = 7; int collDateIndex = 3; int taxParentIndex = 28; int geoParentIndex = 29; Calendar cal = Calendar.getInstance(); long startTime = System.currentTimeMillis(); IndexWriter[] writers = null; try { for (int i = 0; i < analyzers.length; i++) { files[i] = new File(fileNames[i]); analyzers[i] = new StandardAnalyzer(Version.LUCENE_30); FileUtils.deleteDirectory(files[i]); } System.out.println("Indexing to directory '" + INDEX_DIR + "'..."); long totalRecs = BasicSQLUtils.getCount(dbConn, "SELECT COUNT(*) FROM collectionobject"); long procRecs = 0; Statement stmt = null; Statement stmt2 = null; Statement stmt3 = null; //PreparedStatement pStmt = null; try { writers = new IndexWriter[analyzers.length]; for (int i = 0; i < files.length; i++) { writers[i] = new IndexWriter(FSDirectory.open(files[i]), analyzers[i], true, IndexWriter.MaxFieldLength.LIMITED); } System.out.println("Total Records: " + totalRecs); stmt = dbConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); stmt2 = dbConn2.createStatement(); stmt3 = dbConn3.createStatement(); stmt3.setFetchSize(Integer.MIN_VALUE); //pStmt = dbConn3.prepareStatement("SELECT Text1 FROM preparation WHERE CollectionObjectID = ? AND Text1 IS NOT NULL"); String sql = createQuery(); System.out.println(sql); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData md = rs.getMetaData(); StringBuilder indexStr = new StringBuilder(); StringBuilder contents = new StringBuilder(); StringBuilder sb = new StringBuilder(); while (rs.next()) { String id = rs.getString(idIndex + 1); Document doc = new Document(); doc.add(new Field("id", id.toString(), Field.Store.YES, Field.Index.ANALYZED)); indexStr.setLength(0); contents.setLength(0); sb.setLength(0); int cnt = 0; for (int i = 0; i < idIndex; i++) { if (includeCol[i] == 1) { String val = rs.getString(i + 1); if (i == 0) { val = val.replaceFirst("^0+(?!$)", ""); } //System.out.println(i+" "+cnt+" "+md.getColumnName(i+1)+" ["+(StringUtils.isNotEmpty(val) ? val : " ")+"] "); contents.append(StringUtils.isNotEmpty(val) ? val : " "); contents.append('\t'); cnt++; } } indexStr.append(contents); Date collDate = rs.getDate(collDateIndex); if (collDate != null) { cal.setTime(collDate); String yearStr = Integer.toString(cal.get(Calendar.YEAR)); indexStr.append(yearStr); indexStr.append('\t'); doc.add(new Field("yr", yearStr, Field.Store.YES, Field.Index.ANALYZED)); } sb.setLength(0); for (int i = idIndex; i < colToTblId.length; i++) { if (i > idIndex) sb.append(','); sb.append(String.format("%d=%d", colToTblId[i], rs.getInt(i + 1))); } doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); //writers[0].addDocument(doc); /////////////////////////////////////////////// // Catalog Number /////////////////////////////////////////////// String catNum = rs.getString(1); if (StringUtils.isNotEmpty(catNum)) { doc.add(new Field("cn", catNum, Field.Store.YES, Field.Index.ANALYZED)); } /////////////////////////////////////////////// // Image Name in Text1 /////////////////////////////////////////////// boolean hasName = false; /*try { int idd = Integer.parseInt(id); //pStmt.setInt(1, idd); //ResultSet rsp = pStmt.executeQuery(); ResultSet rsp = stmt3.executeQuery(String.format("SELECT Text1 FROM preparation WHERE CollectionObjectID = %d AND Text1 IS NOT NULL", idd)); if (rsp.next()) { String imgName = rsp.getString(1); if (StringUtils.isNotEmpty(imgName)) { String nm = FilenameUtils.getName(imgName); doc.add(new Field("im", nm, Field.Store.NO, Field.Index.ANALYZED)); contents.append(nm); hasName = true; } } rsp.close(); } catch (SQLException e) {e.printStackTrace();} */ if (!hasName) { contents.append(" "); } contents.append('\t'); /////////////////////////////////////////////// // Collector (Agent) /////////////////////////////////////////////// String dataStr = buildStr(rs, sb, 17, 18, 19); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("ag", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); /////////////////////////////////////////////// // Locality /////////////////////////////////////////////// dataStr = buildStr(rs, sb, 9, 10, 11, 12, 13, 14); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("lc", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //writers[2].addDocument(doc); //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); /////////////////////////////////////////////// // Taxon /////////////////////////////////////////////// dataStr = buildStr(rs, sb, 5, 6); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("tx", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //writers[3].addDocument(doc); int taxId = rs.getInt(taxIndex); boolean taxOK = !rs.wasNull(); int taxPId = rs.getInt(taxParentIndex); taxOK = taxOK && !rs.wasNull(); int geoId = rs.getInt(geoIndex); boolean geoOK = !rs.wasNull(); int geoPId = rs.getInt(geoParentIndex); geoOK = geoOK && !rs.wasNull(); int ceId = rs.getInt(ceIndex); boolean ceOK = !rs.wasNull(); if (taxOK) { addHigherTaxa(stmt2, doc, indexStr, taxId, taxPId, rs.getInt(taxNameIndex + 1), rs.getString(taxNameIndex)); addAuthor(stmt2, doc, indexStr, taxId); } if (geoOK) { addCountry(stmt2, doc, indexStr, geoId, geoPId, rs.getInt(geoNameIndex + 1), rs.getString(geoNameIndex)); } if (ceOK) { addHost(stmt2, doc, indexStr, ceId); } //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("cs", indexStr.toString(), Field.Store.NO, Field.Index.ANALYZED)); //doc.add(new Field("contents", contents.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); writers[0].addDocument(doc); //System.out.println(procRecs+" "+rs.getString(1)); procRecs++; if (procRecs % 1000 == 0) { System.out.println(procRecs); } if (procRecs % 100000 == 0) { System.out.println("Optimizing..."); writers[0].optimize(); } } rs.close(); } catch (SQLException sqlex) { sqlex.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.out.println("IOException adding Lucene Document: " + e.getMessage()); } finally { if (stmt != null) { try { if (stmt != null) stmt.close(); if (stmt2 != null) stmt2.close(); if (stmt3 != null) stmt3.close(); } catch (SQLException e) { e.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } finally { for (Analyzer a : analyzers) { a.close(); } analyzers = null; for (IndexWriter writer : writers) { try { System.out.println("Optimizing..."); writer.optimize(); writer.close(); System.out.println("Done Optimizing."); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } writer = null; } long endTime = System.currentTimeMillis(); System.out.println("Time: " + (endTime - startTime) / 1000); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AddressTagTable.java
public MSSBamAddressTagBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long AddressId, long TagId) { final String S_ProcName = "readBuffByIdIdx"; try {/*from w w w . j a va 2s. co m*/ Connection cnx = schema.getCnx(); String sql = S_sqlSelectAddressTagBuff + "WHERE " + "adtg.AddressId = " + Long.toString(AddressId) + " " + "AND " + "adtg.TagId = " + Long.toString(TagId) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); if (resultSet.next()) { MSSBamAddressTagBuff buff = unpackAddressTagResultSetToBuff(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); } }
From source file:edu.ku.brc.specify.conversion.IdTableMapper.java
/** * Map all the old IDs to new IDs/*from www. j a va2 s. c o m*/ * @param sqlArg the string to use to fill the map */ public void mapAllIdsNoIncrement(final String sqlArg, final Integer numRecords) { log.debug("mapAllIdsNoIncrement with sql: " + sqlArg); this.sql = sqlArg; int mappingCount = numRecords != null ? numRecords : getMapCount(mapTableName); wasEmpty = mappingCount == 0; if (doDelete || mappingCount == 0) { BasicSQLUtils.deleteAllRecordsFromTable(oldConn, mapTableName, BasicSQLUtils.myDestinationServerType); if (frame != null) { String dMsg = "Mapping " + mapTableName; frame.setDesc(dMsg); log.debug(dMsg); } try { log.debug("Executing: " + sql); 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()); } } int cnt = 0; if (rs.first()) { do { int oldIndex = rs.getInt(1); int toIndex = rs.getInt(2); pStmt.setInt(1, oldIndex); // Old Index pStmt.setInt(2, toIndex); // New Index if (pStmt.executeUpdate() != 1) { String msg = String.format("Error writing to Map table[%s] old: %d new: %d", mapTableName, oldIndex, toIndex); log.error(msg); throw new RuntimeException(msg); } if (frame != null) { if (cnt % 1000 == 0) { frame.setProcess(cnt); } } else { if (cnt % 2000 == 0) { log.debug("Mapped " + cnt + " records from " + tableName); } } cnt++; } while (rs.next()); log.info("Mapped " + cnt + " records from " + tableName); } 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(IdTableMapper.class, ex); 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:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AddressTable.java
public MSSBamAddressBuff readBuff(MSSBamAuthorization Authorization, MSSBamAddressPKey PKey) { final String S_ProcName = "readBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }//from w ww . j av a2 s. c o m try { Connection cnx = schema.getCnx(); long AddressId = PKey.getRequiredAddressId(); String sql = S_sqlSelectAddressBuff + "WHERE " + "adr.AddressId = " + Long.toString(AddressId) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); if (resultSet.next()) { MSSBamAddressBuff buff = unpackAddressResultSetToBuff(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); } }
From source file:org.ala.lucene.ExternalIndexLoader.java
/** * Load the datasets//from ww w .j a va 2 s. c o m * * @throws Exception */ public void loadDatasets() throws Exception { logger.info("Starting syncing data resource information...."); Connection conn = collectoryDataSource.getConnection(); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery( "select dr.uid, dr.guid, dr.name, dr.acronym as acronym, dp.name as data_provider_name, dr.pub_description as description " + "from data_resource dr " + "left join data_provider dp ON dp.id=dr.data_provider_id "); SolrServer solrServer = solrUtils.getSolrServer(); solrServer.deleteByQuery("idxtype:" + IndexedTypes.DATASET); while (rs.next()) { String uid = rs.getString("uid"); String externalGuid = rs.getString("guid"); String name = rs.getString("name"); String acronym = rs.getString("acronym"); String dataProviderName = rs.getString("data_provider_name"); String description = rs.getString("description"); SolrInputDocument doc = new SolrInputDocument(); doc.addField("guid", baseUrlForCollectory + uid); doc.addField("url", baseUrlForCollectory + uid); doc.addField("id", baseUrlForCollectory + uid); doc.addField("name", name); if (externalGuid != null) { doc.addField("otherGuid", externalGuid); } if (acronym != null) { doc.addField("acronym", acronym); } doc.addField("dataProviderName", dataProviderName); doc.addField("description", description); doc.addField("idxtype", IndexedTypes.DATASET); // 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 data resource information."); }
From source file:com.taobao.datax.plugins.writer.mysqlwriter.MysqlWriter.java
@Override public int finish() { Statement stmt = null;//from w ww . j a v a2s . com try { StringBuilder sb = new StringBuilder(); String PATTERN = "row \\d+"; Pattern p = Pattern.compile(PATTERN); Set<String> rowCounter = new HashSet<String>(); stmt = this.connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs; sb.setLength(0); sb.append('\n'); int warnCnts = 0; rs = stmt.executeQuery("SHOW WARNINGS;"); while (rs.next()) { if (warnCnts++ < 32) { sb.append(rs.getString(1)).append(" ").append(rs.getInt(2)).append(" ").append(rs.getString(3)) .append("\n"); } Matcher matcher = p.matcher(rs.getString(3)); if (matcher.find()) { rowCounter.add(matcher.group()); } } if (!StringUtils.isBlank(sb.toString())) { if (rowCounter.size() > 32) { sb.append("More error messages hidden ..."); } this.logger.warn(sb); if (this.limit >= 1 && rowCounter.size() >= this.limit) { this.logger.error(String.format("%d rows data failed in loading.", rowCounter.size())); return PluginStatus.FAILURE.value(); } else if (this.limit > 0 && this.limit < 1 && this.lineCounter > 0) { double rate = (double) rowCounter.size() / (double) this.lineCounter; if (rate >= this.limit) { this.logger.error(String.format("%.1f%% data failed in loading.", rate * 100)); return PluginStatus.FAILURE.value(); } } else { this.logger.warn( String.format("MysqlWriter found %d rows data format error .", rowCounter.size())); // this.getMonitor().setFailedLines(rowCounter.size()); } } } catch (SQLException e) { } finally { try { if (stmt != null) stmt.close(); if (null != this.connection) this.connection.close(); } catch (Exception e) { } } return PluginStatus.SUCCESS.value(); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AccessSecurityTable.java
public MSSBamAccessSecurityBuff[] readBuffByUNameIdx(MSSBamAuthorization Authorization, String Name) { final String S_ProcName = "readBuffByUNameIdx"; try {// w ww.j av a2 s . co m Connection cnx = schema.getCnx(); String sql = S_sqlSelectAccessSecurityBuff + "WHERE " + "asec.Name = " + MSSBamPg8Schema.getQuotedString(Name) + " " + "ORDER BY " + "asec.Id ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamAccessSecurityBuff> buffList = new ArrayList<MSSBamAccessSecurityBuff>(); while (resultSet.next()) { MSSBamAccessSecurityBuff buff = unpackAccessSecurityResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamAccessSecurityBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AttachmentTable.java
public MSSBamAttachmentBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "readAllBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*www . j a va2 s .c om*/ try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectAttachmentBuff + "ORDER BY " + "attc.AttachmentId ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamAttachmentBuff> buffList = new ArrayList<MSSBamAttachmentBuff>(); while (resultSet.next()) { MSSBamAttachmentBuff buff = unpackAttachmentResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamAttachmentBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:ca.on.gov.jus.icon.common.iconcodetables.IconCodeTablesManager.java
private IconCodeTable getICONCodesTableList() { IconCodeTable iconCodesTableList = null; String selectSql = null;/*from w w w . j av a 2s . co m*/ Connection oracleConnection = ReportsConnectionManager.getPooledOracleConnection(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; if (null != oracleConnection) { selectSql = "" + "SELECT " + " ICONADMIN.ICON_TABLES_CODE.CODE, " + " ICONADMIN.ICON_TABLES_CODE.DESCRIPTION, " + " ICONADMIN.ICON_TABLES_CODE.TABLE_PASS " + "FROM " + " ICONADMIN.ICON_TABLES_CODE " + "ORDER BY " + " ICONADMIN.ICON_TABLES_CODE.DESCRIPTION ASC "; try { preparedStatement = oracleConnection.prepareStatement(selectSql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); resultSet = preparedStatement.executeQuery(); resultSet.last(); int resultSetCount = resultSet.getRow(); //logger.info("resultSetCount: " + resultSetCount); resultSet.beforeFirst(); if (resultSetCount > 0) { iconCodesTableList = new IconCodeTable("ICON_CodeTablesList", "ICON Codes Table List"); } while (resultSet.next()) { IconCodeTable iconCodeTable = new IconCodeTable(resultSet.getString("CODE"), resultSet.getString("DESCRIPTION")); iconCodeTable.setCodeTablePass(resultSet.getString("TABLE_PASS")); //Null it so that it can not be used that way iconCodeTable.setCodeTableValues(null); iconCodesTableList.getCodeTableValues().put(resultSet.getString("CODE"), iconCodeTable); } } catch (SQLException e) { e.printStackTrace(); } finally { try { //clean up if (null != resultSet) { resultSet.close(); resultSet = null; } if (null != preparedStatement) { preparedStatement.close(); preparedStatement = null; } //Should never close the pooled connection // if(null != oracleConnection){ // oracleConnection.close(); // oracleConnection = null; // } } catch (SQLException e1) { } } } return iconCodesTableList; }