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.MSSBamPg8BaseDomainTable.java
public void createBaseDomain(MSSBamAuthorization Authorization, MSSBamBaseDomainBuff Buff) { final String S_ProcName = "createBaseDomain "; try {/* w w w .j a v a 2 s. co m*/ Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); String sql = "INSERT INTO mssbam110.basedom( " + "id" + " )" + "VALUES ( " + 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 insert, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AddressTagTable.java
public void createAddressTag(MSSBamAuthorization Authorization, MSSBamAddressTagBuff Buff) { final String S_ProcName = "createAddressTag "; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from w w w. ja v a2s . com*/ try { Connection cnx = schema.getCnx(); long AddressId = Buff.getRequiredAddressId(); long TagId = Buff.getRequiredTagId(); String TagValue = Buff.getRequiredTagValue(); int Revision = 1; String sql = "INSERT INTO mssbam110.ctcaddr_tag( " + "addressid, " + "tagid, " + "tagvalue" + ", revision )" + "VALUES ( " + AddressId + ", " + TagId + ", " + MSSBamPg8Schema.getQuotedString(TagValue) + ", " + Integer.toString(Revision) + " )"; 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 insert, not " + rowsAffected); } Buff.setRequiredRevision(Revision); Buff.setRequiredRevision(Revision); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AttachmentTagTable.java
public void createAttachmentTag(MSSBamAuthorization Authorization, MSSBamAttachmentTagBuff Buff) { final String S_ProcName = "createAttachmentTag "; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }// w w w .jav a 2 s . com try { Connection cnx = schema.getCnx(); long AttachmentId = Buff.getRequiredAttachmentId(); long TagId = Buff.getRequiredTagId(); String TagValue = Buff.getRequiredTagValue(); int Revision = 1; String sql = "INSERT INTO mssbam110.ctcattch_tag( " + "attachmentid, " + "tagid, " + "tagvalue" + ", revision )" + "VALUES ( " + AttachmentId + ", " + TagId + ", " + MSSBamPg8Schema.getQuotedString(TagValue) + ", " + Integer.toString(Revision) + " )"; 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 insert, not " + rowsAffected); } Buff.setRequiredRevision(Revision); Buff.setRequiredRevision(Revision); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:DbManager.java
/** * Initialize the DbManager./*from www .j a v a 2 s . c o m*/ * * @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:net.xqx.controller.web.QyzzController.java
/** * ?/* ww w. j av a 2 s. co m*/ * * @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:com.mongosqlmigrator.harsha.sql.DocBuilder.java
public void execute() throws Exception { String url = importer.getConfig().dataSources.get(null).getProperty("url"); String user = importer.getConfig().dataSources.get(null).getProperty("user"); String password = importer.getConfig().dataSources.get(null).getProperty("password"); batchSize = Integer.valueOf(importer.getConfig().dataSources.get(null).getProperty("batch-size")); Entity rootEntity = importer.getConfig().document.entities.get(0); String driverName = importer.getConfig().dataSources.get(null).getProperty(DRIVER); //Set the fetch size depending on SQL type if (batchSize == -1 && driverName.contains("mysql")) batchSize = Integer.MIN_VALUE; else if (batchSize == -1) batchSize = 0;/*from ww w.java2 s . com*/ Class.forName(driverName).newInstance(); conn = DriverManager.getConnection(url, user, password); subConnection = DriverManager.getConnection(url, user, password); //set the PK for future use importer.getWriter().setPrimaryKey(rootEntity.pk); if (rootEntity != null && rootEntity.isDocRoot) { String rootQuery = rootEntity.allAttributes.get("query"); stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setMaxRows(0); stmt.setFetchSize(batchSize); rs = stmt.executeQuery(rootQuery); int i = 0; List<Map<String, Object>> entityList = new ArrayList<Map<String, Object>>(); long t1 = System.currentTimeMillis(); while (rs.next()) { if (i == importer.getAutoCommitSize()) { long t2 = System.currentTimeMillis(); log.info("Time taken to Read " + i + " documents from SQL : " + (t2 - t1) + " ms"); importer.getWriter().writeToNoSQL(entityList); entityList = new ArrayList<Map<String, Object>>(); i = 0; t1 = System.currentTimeMillis(); } params = new HashMap<String, String>(); entityList.add(getFields(processor.toMap(rs), rs, rootEntity, null, null)); i++; } importer.getWriter().writeToNoSQL(entityList); } conn.close(); subConnection.close(); }
From source file:com.alibaba.wasp.jdbc.TestJdbcStatement.java
@Test public void testStatement() throws SQLException, IOException, InterruptedException { Statement stat = conn.createStatement(); assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability()); conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability()); // ignored//from w w w .j av a 2 s . c o m stat.setCursorName("x"); // fixed return value assertEquals(stat.getFetchDirection(), ResultSet.FETCH_FORWARD); // ignored stat.setFetchDirection(ResultSet.FETCH_REVERSE); // ignored stat.setMaxFieldSize(100); assertEquals(conf.getInt(FConstants.WASP_JDBC_FETCHSIZE, FConstants.DEFAULT_WASP_JDBC_FETCHSIZE), stat.getFetchSize()); stat.setFetchSize(10); assertEquals(10, stat.getFetchSize()); stat.setFetchSize(0); assertEquals(conf.getInt(FConstants.WASP_JDBC_FETCHSIZE, FConstants.DEFAULT_WASP_JDBC_FETCHSIZE), stat.getFetchSize()); assertEquals(ResultSet.TYPE_FORWARD_ONLY, stat.getResultSetType()); Statement stat2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, stat2.getResultSetType()); assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stat2.getResultSetHoldability()); assertEquals(ResultSet.CONCUR_READ_ONLY, stat2.getResultSetConcurrency()); assertEquals(0, stat.getMaxFieldSize()); assertTrue(!((JdbcStatement) stat2).isClosed()); stat2.close(); assertTrue(((JdbcStatement) stat2).isClosed()); ResultSet rs; int count; boolean result; stat.execute("CREATE TABLE TEST {REQUIRED INT64 ID;" + "REQUIRED STRING VALUE; }PRIMARY KEY(ID), " + "ENTITY GROUP ROOT,ENTITY GROUP KEY(ID);"); TEST_UTIL.waitTableEnabled(Bytes.toBytes("TEST"), 5000); ResultInHBasePrinter.printMETA(conf, LOG); ResultInHBasePrinter.printFMETA(conf, LOG); ResultInHBasePrinter.printTable("test", "WASP_ENTITY_TEST", conf, LOG); conn.getTypeMap(); // this method should not throw an exception - if not supported, this // calls are ignored assertEquals(ResultSet.CONCUR_READ_ONLY, stat.getResultSetConcurrency()); // stat.cancel(); stat.setQueryTimeout(10); assertTrue(stat.getQueryTimeout() == 10); stat.setQueryTimeout(0); assertTrue(stat.getQueryTimeout() == 0); // assertThrows(SQLErrorCode.INVALID_VALUE_2, stat).setQueryTimeout(-1); assertTrue(stat.getQueryTimeout() == 0); trace("executeUpdate"); count = stat.executeUpdate("INSERT INTO TEST (ID,VALUE) VALUES (1,'Hello')"); assertEquals(1, count); count = stat.executeUpdate("INSERT INTO TEST (VALUE,ID) VALUES ('JDBC',2)"); assertEquals(1, count); count = stat.executeUpdate("UPDATE TEST SET VALUE='LDBC' WHERE ID=1"); assertEquals(1, count); count = stat.executeUpdate("DELETE FROM TEST WHERE ID=-1"); assertEquals(0, count); count = stat.executeUpdate("DELETE FROM TEST WHERE ID=1"); assertEquals(1, count); count = stat.executeUpdate("DELETE FROM TEST WHERE ID=2"); assertEquals(1, count); result = stat.execute("INSERT INTO TEST(ID,VALUE) VALUES(1,'Hello')"); assertTrue(!result); result = stat.execute("INSERT INTO TEST(VALUE,ID) VALUES('JDBC',2)"); assertTrue(!result); result = stat.execute("UPDATE TEST SET VALUE='LDBC' WHERE ID=2"); assertTrue(!result); result = stat.execute("DELETE FROM TEST WHERE ID=1"); assertTrue(!result); result = stat.execute("DELETE FROM TEST WHERE ID=2"); assertTrue(!result); result = stat.execute("DELETE FROM TEST WHERE ID=3"); assertTrue(!result); // getMoreResults rs = stat.executeQuery("SELECT ID,VALUE FROM TEST WHERE ID=1"); assertFalse(stat.getMoreResults()); assertThrows(SQLErrorCode.OBJECT_CLOSED, rs).next(); assertTrue(stat.getUpdateCount() == -1); count = stat.executeUpdate("DELETE FROM TEST WHERE ID=1"); assertFalse(stat.getMoreResults()); assertTrue(stat.getUpdateCount() == -1); WaspAdmin admin = new WaspAdmin(TEST_UTIL.getConfiguration()); admin.disableTable("TEST"); stat.execute("DROP TABLE TEST"); admin.waitTableNotLocked("TEST".getBytes()); stat.executeUpdate("DROP TABLE IF EXISTS TEST"); assertTrue(stat.getWarnings() == null); stat.clearWarnings(); assertTrue(stat.getWarnings() == null); assertTrue(conn == stat.getConnection()); admin.close(); stat.close(); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java
public void createChain(MSSBamAuthorization Authorization, MSSBamChainBuff Buff) { final String S_ProcName = "createChain "; try {/* ww w .j ava 2 s . c o m*/ Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); long TableId = Buff.getRequiredTableId(); String Suffix = Buff.getOptionalSuffix(); Long PrevRelationId = Buff.getOptionalPrevRelationId(); Long NextRelationId = Buff.getOptionalNextRelationId(); String sql = "INSERT INTO mssbam110.chain_def( " + "id, " + "tableid, " + "suffix, " + "prevrelationid, " + "nextrelationid" + " )" + "VALUES ( " + Id + ", " + TableId + ", " + MSSBamPg8Schema.getQuotedString(Suffix) + ", " + ((PrevRelationId == null) ? "null" : PrevRelationId.toString()) + ", " + ((NextRelationId == null) ? "null" : NextRelationId.toString()) + " )"; 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 insert, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java
/** * //from w w w .j a v a2 s. c om */ public void process() { //String sql = "SELECT collector_name FROM raw WHERE collector_name IS NOT NULL AND collector_name LIKE '%;%' limit 4000,1000"; String sql = "SELECT collector_name FROM raw WHERE collector_name IS NOT NULL limit 4000,1000"; try { Statement stmt = oldDBConn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { String str = rs.getString(1); System.out.println("\n" + str); parseForNames(str); } rs.close(); stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.linkedin.pinot.integration.tests.RealtimeClusterIntegrationTest.java
@BeforeClass public void setUp() throws Exception { // Start ZK and Kafka startZk();//from w ww . ja v a 2 s. c om kafkaStarters = KafkaStarterUtils.startServers(getKafkaBrokerCount(), KafkaStarterUtils.DEFAULT_KAFKA_PORT, KafkaStarterUtils.DEFAULT_ZK_STR, KafkaStarterUtils.getDefaultKafkaConfiguration()); // Create Kafka topic createKafkaTopic(KAFKA_TOPIC, KafkaStarterUtils.DEFAULT_ZK_STR); // Start the Pinot cluster startController(); startBroker(); startServer(); // Unpack data final List<File> avroFiles = unpackAvroData(_tmpDir, SEGMENT_COUNT); File schemaFile = getSchemaFile(); // Load data into H2 ExecutorService executor = Executors.newCachedThreadPool(); setupH2AndInsertAvro(avroFiles, executor); // Initialize query generator setupQueryGenerator(avroFiles, executor); // Push data into the Kafka topic pushAvroIntoKafka(avroFiles, executor, KAFKA_TOPIC); // Wait for data push, query generator initialization and H2 load to complete executor.shutdown(); executor.awaitTermination(10, TimeUnit.MINUTES); // Create Pinot table setUpTable("mytable", "DaysSinceEpoch", "daysSinceEpoch", KafkaStarterUtils.DEFAULT_ZK_STR, KAFKA_TOPIC, schemaFile, avroFiles.get(0)); // Wait until the Pinot event count matches with the number of events in the Avro files long timeInFiveMinutes = System.currentTimeMillis() + 5 * 60 * 1000L; Statement statement = _connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); statement.execute("select count(*) from mytable"); ResultSet rs = statement.getResultSet(); rs.first(); int h2RecordCount = rs.getInt(1); rs.close(); waitForRecordCountToStabilizeToExpectedCount(h2RecordCount, timeInFiveMinutes); }