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.MSSBamPg8BlobDefTable.java
public MSSBamBlobDefBuff[] readBuffByContNextIdx(MSSBamAuthorization Authorization, long ValueContainerId, Long NextId) {/* w ww . j a va 2s. c o m*/ final String S_ProcName = "readBuffByContNextIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBlobDefBuff + "WHERE " + "val.ValueContainerId = " + Long.toString(ValueContainerId) + " " + "AND " + ((NextId == null) ? "val.NextId is null " : "val.NextId = " + NextId.toString() + " ") + "ORDER BY " + "anyo.Id ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamBlobDefBuff> buffList = new ArrayList<MSSBamBlobDefBuff>(); while (resultSet.next()) { MSSBamBlobDefBuff buff = unpackBlobDefResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamBlobDefBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:edu.ku.brc.specify.conversion.AgentConverter.java
protected void parseAndFixMultiLineAddresses() { String whereStr = " FROM address a WHERE Address like '%\r\n%'"; String sql = "SELECT COUNT(*)" + whereStr; if (BasicSQLUtils.getCountAsInt(sql) < 1) { return;/* ww w. j av a 2 s . c o m*/ } sql = "SELECT AddressID, Address" + whereStr; Statement stmt = null; //PreparedStatement pStmt = null; try { // pStmt = newDBConn.prepareStatement("UPDATE address SET Address=?, Address2=?, City=?, State=?, PostalCode=? WHERE AddressID = ?"); stmt = newDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(sql); HashSet<Integer> hashSet = new HashSet<Integer>(); while (rs.next()) { String[] toks = StringUtils.split(rs.getString(2), "\r\n"); hashSet.add(toks.length); } rs.close(); for (Integer i : (Integer[]) hashSet.toArray()) { System.out.println(i); } System.out.println(); } catch (Exception ex) { } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BoolDefTable.java
public void updateBoolDef(MSSBamAuthorization Authorization, MSSBamBoolDefBuff Buff) { final String S_ProcName = "updateBoolDef"; try {/* w ww. j a va2 s. c o m*/ Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); Boolean InitValue = Buff.getOptionalInitValue(); Boolean DefaultValue = Buff.getOptionalDefaultValue(); String FalseString = Buff.getOptionalFalseString(); String TrueString = Buff.getOptionalTrueString(); String NullString = Buff.getOptionalNullString(); String sql = "UPDATE mssbam110.bool_def " + "SET " + "Id = " + MSSBamPg8Schema.getInt64String(Id) + ", " + "InitVal = " + ((InitValue != null) ? MSSBamPg8Schema.getBoolString(InitValue) : "null") + ", " + "DefVal = " + ((DefaultValue != null) ? MSSBamPg8Schema.getBoolString(DefaultValue) : "null") + ", " + "FalseString = " + ((FalseString != null) ? MSSBamPg8Schema.getQuotedString(FalseString) : "null") + ", " + "TrueString = " + ((TrueString != null) ? MSSBamPg8Schema.getQuotedString(TrueString) : "null") + ", " + "NullString = " + ((NullString != null) ? MSSBamPg8Schema.getQuotedString(NullString) : "null") + " " + "WHERE " + "Id = " + Long.toString(Id) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int rowsAffected = stmt.executeUpdate(sql); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by update, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BlobDefTable.java
public void updateBlobDef(MSSBamAuthorization Authorization, MSSBamBlobDefBuff Buff) { final String S_ProcName = "updateBlobDef"; try {//w w w .j av a 2 s .c o m Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); int MaxLen = Buff.getRequiredMaxLen(); byte[] InitValue = Buff.getOptionalInitValue(); byte[] DefaultValue = Buff.getOptionalDefaultValue(); byte[] NullValue = Buff.getOptionalNullValue(); byte[] UnknownValue = Buff.getOptionalUnknownValue(); String sql = "UPDATE mssbam110.blob_def " + "SET " + "Id = " + MSSBamPg8Schema.getInt64String(Id) + ", " + "MaxLen = " + MSSBamPg8Schema.getInt32String(MaxLen) + ", " + "InitVal = " + ((InitValue != null) ? MSSBamPg8Schema.getBlobString(InitValue) : "null") + ", " + "DefVal = " + ((DefaultValue != null) ? MSSBamPg8Schema.getBlobString(DefaultValue) : "null") + ", " + "NullVal = " + ((NullValue != null) ? MSSBamPg8Schema.getBlobString(NullValue) : "null") + ", " + "UnknownVal = " + ((UnknownValue != null) ? MSSBamPg8Schema.getBlobString(UnknownValue) : "null") + " " + "WHERE " + "Id = " + Long.toString(Id) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int rowsAffected = stmt.executeUpdate(sql); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by update, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BoolDefTable.java
public void deleteBoolDef(MSSBamAuthorization Authorization, MSSBamBoolDefBuff Buff) { final String S_ProcName = "deleteBoolDef"; try {//from www . j a v a2 s. c o m Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); Boolean InitValue = Buff.getOptionalInitValue(); Boolean DefaultValue = Buff.getOptionalDefaultValue(); String FalseString = Buff.getOptionalFalseString(); String TrueString = Buff.getOptionalTrueString(); String NullString = Buff.getOptionalNullString(); String sql = "DELETE FROM mssbam110.bool_def " + "WHERE " + "Id = " + Long.toString(Id) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int rowsAffected = stmt.executeUpdate(sql); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by delete, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BlobDefTable.java
public void deleteBlobDef(MSSBamAuthorization Authorization, MSSBamBlobDefBuff Buff) { final String S_ProcName = "deleteBlobDef"; try {//from w w w . java2s . c o m Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); int MaxLen = Buff.getRequiredMaxLen(); byte[] InitValue = Buff.getOptionalInitValue(); byte[] DefaultValue = Buff.getOptionalDefaultValue(); byte[] NullValue = Buff.getOptionalNullValue(); byte[] UnknownValue = Buff.getOptionalUnknownValue(); String sql = "DELETE FROM mssbam110.blob_def " + "WHERE " + "Id = " + Long.toString(Id) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int rowsAffected = stmt.executeUpdate(sql); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by delete, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java
/** * @param oldDBConn/*from w ww. j a va2s . c o m*/ * @param newDBConn */ public void doSetDisciplineIntoCEs(final Connection oldDBConn, final Connection newDBConn) { //ProgressFrame frame = conversion.getFrame(); //IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); IdMapperIFace ceMapper = IdMapperMgr.getInstance().addTableMapper("collectingevent", "CollectingEventID", false); HashMap<Integer, Integer> catSeriesToDisciplineHash = new HashMap<Integer, Integer>(); for (CollectionInfo ci : CollectionInfo.getCollectionInfoList()) { catSeriesToDisciplineHash.put(ci.getCatSeriesId(), ci.getDisciplineId()); } //catSeriesToDisciplineHash.put(0, 3); //catSeriesToDisciplineHash.put(-568842536, 7); String sql = "SELECT csd.CatalogSeriesID, ce.CollectingEventID FROM catalogseriesdefinition AS csd " + "Inner Join collectingevent AS ce ON csd.ObjectTypeID = ce.BiologicalObjectTypeCollectedID"; PreparedStatement pStmt = null; Statement stmt = null; try { pStmt = newDBConn .prepareStatement("UPDATE collectingevent SET DisciplineID=? WHERE CollectingEventID=?"); int totalCnt = BasicSQLUtils.getNumRecords(oldDBConn, "collectingevent"); stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); ResultSet rs = stmt.executeQuery(sql); if (frame != null) { frame.setProcess(0, totalCnt); frame.setDesc("Setting Discipline Ids in CollectingEvents"); } int count = 0; while (rs.next()) { int catSerId = rs.getInt(1); int id = rs.getInt(2); Integer dispId = catSeriesToDisciplineHash.get(catSerId); if (dispId != null) { Integer newId = ceMapper.get(id); if (newId != null) { pStmt.setInt(1, dispId); pStmt.setInt(2, newId); pStmt.executeUpdate(); } else { System.err.println(String.format("Unable to map oldId %d", id)); } } else { System.err.println(String.format("Unable to map Cat Series %d to a discipline", catSerId)); } count++; if (count % 1000 == 0) { if (frame != null) { frame.setProcess(count); } else { log.info(String.format("CE Records: %d / %d", count, totalCnt)); } } } rs.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (pStmt != null) pStmt.close(); if (stmt != null) stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:jef.database.DbMetaData.java
private <T> T select0(Connection conn, String sql, ResultSetExtractor<T> rst, List<?> objs, SqlLog debug) throws SQLException { // ???ResultSet if (!rst.autoClose()) { throw new UnsupportedOperationException(); }/* w w w. j a v a 2 s . co m*/ PreparedStatement st = null; ResultSet rs = null; DatabaseDialect profile = getProfile(); try { debug.ensureCapacity(sql.length() + 30); debug.append(sql).append(" | ", getTransactionId()); st = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); if (objs != null) { BindVariableContext context = new BindVariableContext(st, profile, debug); context.setVariables(objs); } // ? MySQLBUG limit=1 rst.apply(st); rs = st.executeQuery(); return rst.transformer(new ResultSetImpl(rs, profile)); } catch (SQLException e) { DebugUtil.setSqlState(e, sql); throw e; } finally { DbUtils.close(rs); DbUtils.close(st); debug.output(); } }
From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java
/** * @param oldDBConn// w w w .j a va2 s . co m * @param newDBConn */ public void doSetDisciplineIntoLocalities(final Connection oldDBConn, final Connection newDBConn) { TableWriter tblWriter = convLogger.getWriter("LocalityDisciplines.html", "Setting Discipline into Localities"); setTblWriter(tblWriter); IdHashMapper.setTblWriter(tblWriter); IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); IdMapperIFace ceMapper = IdMapperMgr.getInstance().addTableMapper("locality", "LocalityID", false); HashMap<Integer, Integer> catSeriesToDisciplineHash = new HashMap<Integer, Integer>(); for (CollectionInfo ci : CollectionInfo.getCollectionInfoList()) { catSeriesToDisciplineHash.put(ci.getCatSeriesId(), ci.getDisciplineId()); } catSeriesToDisciplineHash.put(0, 3); catSeriesToDisciplineHash.put(-568842536, 7); String sql = " SELECT l.LocalityName, l.LocalityID FROM locality AS l Left Join collectingevent AS ce ON l.LocalityID = ce.LocalityID WHERE ce.CollectingEventID IS NULL"; Vector<Object[]> rows = BasicSQLUtils.query(oldDBConn, sql); tblWriter.println(String.format("Unused Localities in the Sp5 database: %d<br>", rows.size())); if (rows.size() > 0) { tblWriter.startTable(); tblWriter.logHdr("Id", "Locality Name"); for (Object[] row : rows) { tblWriter.logObjRow(row); } tblWriter.endTable(); } HashSet<Integer> sharedLocDifObjTypeSet = new HashSet<Integer>(); int numSharedLocaltiesDifObjTypes = 0; // Find the Localities that are being shared. sql = " SELECT * FROM (SELECT l.LocalityID, COUNT(l.LocalityID) cnt, l.LocalityName FROM locality AS l Left Join collectingevent AS ce ON l.LocalityID = ce.LocalityID WHERE ce.CollectingEventID IS NOT NULL GROUP BY l.LocalityID) T1 WHERE cnt > 1"; rows = BasicSQLUtils.query(oldDBConn, sql); tblWriter.println(String.format("Localities being Shared: %d<br>", rows.size())); tblWriter.println("Shared Localities with different ObjectTypes<br>"); if (rows.size() > 0) { tblWriter.startTable(); tblWriter.logHdr("Id", "Count", "Locality Name"); for (Object[] row : rows) { Integer localityId = (Integer) row[0]; sql = String.format( "SELECT COUNT(*) FROM (SELECT ce.BiologicalObjectTypeCollectedID, COUNT(ce.BiologicalObjectTypeCollectedID) " + "FROM locality AS l Left Join collectingevent AS ce ON l.LocalityID = ce.LocalityID " + "WHERE l.LocalityID = %d GROUP BY ce.BiologicalObjectTypeCollectedID) T1", localityId); int count = BasicSQLUtils.getCountAsInt(oldDBConn, sql); if (count > 1) { tblWriter.logObjRow(row); numSharedLocaltiesDifObjTypes++; sharedLocDifObjTypeSet.add(localityId); } } tblWriter.endTable(); } tblWriter.println(String.format("Number of Shared Localities with different ObjectTypes: %d<br>", numSharedLocaltiesDifObjTypes)); sql = "SELECT csd.CatalogSeriesID, l.LocalityID FROM locality AS l Left Join collectingevent AS ce ON l.LocalityID = ce.LocalityID " + "Inner Join catalogseriesdefinition AS csd ON ce.BiologicalObjectTypeCollectedID = csd.ObjectTypeID WHERE ce.CollectingEventID IS NOT NULL " + "GROUP BY l.LocalityID"; PreparedStatement pStmt = null; Statement stmt = null; try { pStmt = newDBConn.prepareStatement("UPDATE locality SET DisciplineID=? WHERE LocalityID=?"); int totalCnt = BasicSQLUtils.getNumRecords(oldDBConn, "locality"); stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); ResultSet rs = stmt.executeQuery(sql); if (frame != null) { frame.setProcess(0, totalCnt); frame.setDesc("Setting Discipline Ids in Locality"); } int count = 0; while (rs.next()) { int catSerId = rs.getInt(1); int id = rs.getInt(2); if (sharedLocDifObjTypeSet.contains(id)) { continue; } Integer dispId = catSeriesToDisciplineHash.get(catSerId); if (dispId != null) { Integer newId = ceMapper.get(id); if (newId != null) { pStmt.setInt(1, dispId); pStmt.setInt(2, newId); pStmt.executeUpdate(); } else { System.err.println(String.format("Unable to map oldId %d", id)); } } else { System.err.println(String.format("Unable to map Cat Series %d to a discipline", catSerId)); } count++; if (count % 1000 == 0) { if (frame != null) { frame.setProcess(count); } else { log.info(String.format("CE Records: %d / %d", count, totalCnt)); } } } rs.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (pStmt != null) pStmt.close(); if (stmt != null) stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:edu.ku.brc.specify.conversion.BasicSQLUtils.java
/** * Returns the number of records in a table * @param connection db connection// w w w. j a va2 s .co m * @param tableName the name of the table * @return the number of records in a table */ public static int getNumRecords(final Connection connection, final String tableName) { try { Integer count = 0; Statement cntStmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = cntStmt.executeQuery("select count(*) from " + tableName); if (rs.first()) { count = rs.getInt(1); if (count == null) { return -1; } } rs.close(); cntStmt.close(); return count; } catch (SQLException ex) { log.error(ex); ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BasicSQLUtils.class, ex); } return -1; }