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:com.clustercontrol.sql.util.AccessDB.java
/** * DB???// ww w.j a v a2s . c o m * * @throws SQLException * @throws ClassNotFoundException */ private void initial() throws SQLException, ClassNotFoundException { //JDBC?? try { Class.forName(m_jdbcDriver); } catch (ClassNotFoundException e) { m_log.info("initial() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } Properties prop = jdbcProps.getProperties(); prop.put("user", m_user); prop.put("password", m_password); try { if (jdbcProps.isLoginTimeoutEnable()) { DriverManager.setLoginTimeout(jdbcProps.getLoginTimeout()); m_log.debug( "enabled loginTimeout (" + jdbcProps.getLoginTimeout() + " [sec]) for \"" + m_url + "\"."); } else { m_log.debug("disabled loginTimeout for \"" + m_url + "\"."); } m_connection = DriverManager.getConnection(m_url, prop); //SQL????Statement? m_statement = m_connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (SQLException e) { m_log.info("initial() database access failure : url = " + m_url + ", : " + e.getClass().getSimpleName() + ", " + e.getMessage()); try { if (m_statement != null) m_statement.close(); } catch (SQLException se) { m_log.info("initial() database closing failure : url = " + m_url + ", " + se.getClass().getSimpleName() + ", " + se.getMessage()); } try { if (m_connection != null) m_connection.close(); } catch (SQLException se) { m_log.info("initial() database closing failure : url = " + m_url + ", " + se.getClass().getSimpleName() + ", " + se.getMessage()); } throw e; } }
From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsProvider.java
@Override public Outcome handleRequest(Exchange exc) throws Exception { Connection con = dataSource.getConnection(); try {//from w ww . j av a 2 s . c om 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.cloudera.sqoop.manager.NetezzaExportManualTest.java
protected void createTableNZ(String tableName, ColumnGenerator... extraCols) throws SQLException { String sqlStatement = getDropTableStatement(tableName); conn.rollback();/*from ww w . j a va2 s. c o m*/ LOG.info("Executing drop statement : " + sqlStatement); PreparedStatement statement = conn.prepareStatement(sqlStatement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); try { statement.executeUpdate(); conn.commit(); } catch (SQLException sqle) { conn.rollback(); } finally { statement.close(); } StringBuilder sb = new StringBuilder(); sb.append("CREATE TABLE "); sb.append(tableName); sb.append(" (id INT NOT NULL PRIMARY KEY, msg VARCHAR(64)"); int colNum = 0; for (ColumnGenerator gen : extraCols) { sb.append(", " + forIdx(colNum++) + " " + gen.getType()); } sb.append(")"); sqlStatement = sb.toString(); LOG.info("Executing create statement : " + sqlStatement); statement = conn.prepareStatement(sqlStatement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); try { statement.executeUpdate(); conn.commit(); } finally { statement.close(); } }
From source file:org.ala.hbase.GeoRegionLoader.java
/** * Sync the geo regions.//from w w w .java 2 s. c o m * * @throws SQLException */ private void syncGeoRegions() throws SQLException { Connection gisConn = gisDataSource.getConnection(); Statement stmt = gisConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt .executeQuery("select gr.id, gr.name, gr.source, gr.acronym, gr.region_type, grt.name as grt_name " + "from geo_region gr " + "inner join geo_region_type grt ON grt.id=gr.region_type " + "where grt.id<5000"); int i = 0; long startTime = System.currentTimeMillis(); while (rs.next()) { //geo region properties int id = rs.getInt("id"); String name = rs.getString("name"); String source = rs.getString("source"); String acronym = rs.getString("acronym"); String regionType = rs.getString("region_type"); String regionTypeName = rs.getString("grt_name"); //store this geo region try { handleRegion(id, name, acronym, source, regionType, regionTypeName); } catch (Exception e) { logger.error(e.getMessage(), e); } i++; if (i % 100 == 0) System.err.println("No of regions synced indexed: " + i); } long finishTime = System.currentTimeMillis(); System.out.println("Geo regions synchronized in " + (finishTime - startTime) / 1000 + " seconds."); rs.close(); stmt.close(); gisConn.close(); }
From source file:SyncMusicServlet.java
private void processAlbumData(String name, String artist, String composer, String year) { Connection conn = null;//ww w .j a v a2 s. c om Statement stmt = null; PreparedStatement pstmt = null; ResultSet rs = null; try { Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String sql = "select * from album where album_title='" + name + "'"; rs = stmt.executeQuery(sql); rs.next(); if (rs.getRow() == 0) { pstmt = conn.prepareStatement( "insert into album (album_title, album_artist, album_composer, release_year) values (?, ?, ?, ?)"); pstmt.setString(1, name); pstmt.setString(2, artist); pstmt.setString(3, composer); pstmt.setString(4, year); pstmt.executeUpdate(); } //out.print(resultJSON); } catch (Exception se) { //out.println("Exception preparing or processing query: " + se); se.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (Exception e) { } } }
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 ww w . j a v a2 s . c o m*/ } 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.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AccessSecurityTable.java
public void createAccessSecurity(MSSBamAuthorization Authorization, MSSBamAccessSecurityBuff Buff) { final String S_ProcName = "createAccessSecurity "; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }//from w ww . j av a 2s . co m try { Connection cnx = schema.getCnx(); short Id = Buff.getRequiredId(); String Name = Buff.getRequiredName(); int Revision = 1; String sql = "INSERT INTO mssbam110.accsec( " + "id, " + "name" + ", revision )" + "VALUES ( " + Id + ", " + MSSBamPg8Schema.getQuotedString(Name) + ", " + 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); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ClusterTable.java
public void createCluster(MSSBamAuthorization Authorization, MSSBamClusterBuff Buff) { final String S_ProcName = "createCluster "; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from w w w .j av a2 s. c o m*/ try { Connection cnx = schema.getCnx(); long Id = schema.nextClusterIdGen(); String FullDomainName = Buff.getRequiredFullDomainName(); int Revision = 1; String sql = "INSERT INTO mssbam110.cluster( " + "id, " + "fulldomainname" + ", revision )" + "VALUES ( " + Id + ", " + MSSBamPg8Schema.getQuotedString(FullDomainName) + ", " + 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.setRequiredId(Id); Buff.setRequiredRevision(Revision); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AccessFrequencyTable.java
public void createAccessFrequency(MSSBamAuthorization Authorization, MSSBamAccessFrequencyBuff Buff) { final String S_ProcName = "createAccessFrequency "; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/* w w w. j a v a 2s .c om*/ try { Connection cnx = schema.getCnx(); short Id = Buff.getRequiredId(); String Name = Buff.getRequiredName(); int Revision = 1; String sql = "INSERT INTO mssbam110.accfreq( " + "id, " + "name" + ", revision )" + "VALUES ( " + Id + ", " + MSSBamPg8Schema.getQuotedString(Name) + ", " + 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); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }