List of usage examples for java.sql ResultSet TYPE_SCROLL_INSENSITIVE
int TYPE_SCROLL_INSENSITIVE
To view the source code for java.sql ResultSet TYPE_SCROLL_INSENSITIVE.
Click Source Link
ResultSet
object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet
. From source file:com.btobits.automator.ant.sql.task.SQLCompareTask.java
@Override public void execute() throws BuildException { validateParameter();//from w w w.j a v a 2s.co m Connection cnn = null; try { Class.forName(driver); cnn = DriverManager.getConnection(url, user, password); final Statement stmt = cnn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); resultSet = stmt.executeQuery(query); verify(); } catch (Exception ex) { resultSet = null; throw new BuildException("Error build: " + ex.getMessage()); } finally { try { cnn.close(); } catch (Exception ex) { } } if (errors.size() > 0) { throw new BuildException(toString(errors)); } }
From source file:org.msec.LogQuery.java
LogQuery(String host, int port, String user, String passwd, String delFieldsConf) throws ClassNotFoundException, SQLException { mysqlHost = host;//from ww w. j a v a2 s . c o m mysqlPort = port; mysqlUser = user; mysqlPasswd = passwd; String url = "jdbc:mysql://" + mysqlHost + ":" + mysqlPort + "/logsys?autoReconnect=true"; conn = DriverManager.getConnection(url, mysqlUser, mysqlPasswd); // stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); //Statement logger.info("Connect to db OK"); builtinColumns = new ArrayList<String>(); builtinColumns.add("reqid"); builtinColumns.add("ip"); builtinColumns.add("clientip"); builtinColumns.add("serverip"); builtinColumns.add("level"); builtinColumns.add("rpcname"); builtinColumns.add("fileline"); builtinColumns.add("function"); builtinColumns.add("instime"); builtinColumns.add("content"); if (delFieldsConf != null) { delFields = new ArrayList<String>(Arrays.asList(delFieldsConf.split(","))); } else { delFields = new ArrayList<String>(); } }
From source file:org.owasp.webgoat.plugin.CrossSiteScriptingLesson6a.java
protected AttackResult injectableQuery(String accountName) { try {/*from ww w .j a v a 2 s. co m*/ Connection connection = DatabaseUtilities.getConnection(getWebSession()); String query = "SELECT * FROM user_data WHERE last_name = '" + accountName + "'"; try { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet results = statement.executeQuery(query); if ((results != null) && (results.first() == true)) { ResultSetMetaData resultsMetaData = results.getMetaData(); StringBuffer output = new StringBuffer(); output.append(writeTable(results, resultsMetaData)); results.last(); // If they get back more than one user they succeeded if (results.getRow() >= 6) { return trackProgress(AttackResult.success("You have succeed: " + output.toString())); } else { return trackProgress(AttackResult.failed("You are close, try again. " + output.toString())); } } else { return trackProgress(AttackResult.failed("No Results Matched. Try Again. ")); } } catch (SQLException sqle) { return trackProgress(AttackResult.failed(sqle.getMessage())); } } catch (Exception e) { e.printStackTrace(); return trackProgress( AttackResult.failed("ErrorGenerating" + this.getClass().getName() + " : " + e.getMessage())); } }
From source file:eu.stratosphere.api.java.io.jdbc.JDBCInputFormat.java
/** * Connects to the source database and executes the query. * * @param ignored// w w w . j a v a2 s. com * @throws IOException */ @Override public void open(InputSplit ignored) throws IOException { try { establishConnection(); statement = dbConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); resultSet = statement.executeQuery(query); } catch (SQLException se) { close(); throw new IllegalArgumentException("open() failed." + se.getMessage(), se); } catch (ClassNotFoundException cnfe) { throw new IllegalArgumentException("JDBC-Class not found. - " + cnfe.getMessage(), cnfe); } }
From source file:gov.nih.nci.migration.MigrationDriver.java
private void encryptDecryptUserInformation() throws EncryptionException, SQLException { Connection connection = getConnection(); //Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); connection.setAutoCommit(false);//from w ww.j a va 2 s. co m ResultSet resultSet = null; if ("oracle".equals(DATABASE_TYPE)) { //resultSet = stmt.executeQuery("SELECT CSM_USER.* FROM CSM_USER FOR UPDATE"); resultSet = stmt.executeQuery("SELECT CSM_USER.* FROM CSM_USER"); } else { resultSet = stmt.executeQuery("SELECT * FROM CSM_USER"); } String userPassword = null; String firstName = null; String lastName = null; String organization = null; String department = null; String title = null; String phoneNumber = null; String emailId = null; String encryptedUserPassword = null; Date expiryDate = null; while (resultSet.next()) { userPassword = resultSet.getString("PASSWORD"); firstName = resultSet.getString("FIRST_NAME"); lastName = resultSet.getString("LAST_NAME"); organization = resultSet.getString("ORGANIZATION"); department = resultSet.getString("DEPARTMENT"); title = resultSet.getString("TITLE"); phoneNumber = resultSet.getString("PHONE_NUMBER"); emailId = resultSet.getString("EMAIL_ID"); if (!StringUtilities.isBlank(userPassword)) { String orgPasswordStr = desEncryption.decrypt(userPassword); encryptedUserPassword = aesEncryption.encrypt(orgPasswordStr); if (!StringUtilities.isBlank(encryptedUserPassword)) { resultSet.updateString("PASSWORD", encryptedUserPassword); } } if (!StringUtilities.isBlank(firstName)) resultSet.updateString("FIRST_NAME", aesEncryption.encrypt(firstName)); if (!StringUtilities.isBlank(lastName)) resultSet.updateString("LAST_NAME", aesEncryption.encrypt(lastName)); if (!StringUtilities.isBlank(organization)) resultSet.updateString("ORGANIZATION", aesEncryption.encrypt(organization)); if (!StringUtilities.isBlank(department)) resultSet.updateString("DEPARTMENT", aesEncryption.encrypt(department)); if (!StringUtilities.isBlank(title)) resultSet.updateString("TITLE", aesEncryption.encrypt(title)); if (!StringUtilities.isBlank(phoneNumber)) resultSet.updateString("PHONE_NUMBER", aesEncryption.encrypt(phoneNumber)); if (!StringUtilities.isBlank(emailId)) resultSet.updateString("EMAIL_ID", aesEncryption.encrypt(emailId)); expiryDate = DateUtils.addDays(Calendar.getInstance().getTime(), Integer.parseInt(getExpiryDays())); resultSet.updateDate("PASSWORD_EXPIRY_DATE", new java.sql.Date(expiryDate.getTime())); System.out.println("Updating user:" + resultSet.getString("LOGIN_NAME")); resultSet.updateRow(); } connection.commit(); }
From source file:org.kuali.rice.kew.docsearch.dao.impl.DocumentSearchDAOJdbcImpl.java
@Override public DocumentSearchResults.Builder findDocuments(final DocumentSearchGenerator documentSearchGenerator, final DocumentSearchCriteria criteria, final boolean criteriaModified, final List<RemotableAttributeField> searchFields) { final int maxResultCap = getMaxResultCap(criteria); try {//from w ww. j a va 2 s. co m final JdbcTemplate template = new JdbcTemplate(dataSource); return template.execute(new ConnectionCallback<DocumentSearchResults.Builder>() { @Override public DocumentSearchResults.Builder doInConnection(final Connection con) throws SQLException { final Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); try { final int fetchIterationLimit = getFetchMoreIterationLimit(); final int fetchLimit = fetchIterationLimit * maxResultCap; statement.setFetchSize(maxResultCap + 1); statement.setMaxRows(fetchLimit + 1); PerformanceLogger perfLog = new PerformanceLogger(); String sql = documentSearchGenerator.generateSearchSql(criteria, searchFields); perfLog.log("Time to generate search sql from documentSearchGenerator class: " + documentSearchGenerator.getClass().getName(), true); LOG.info("Executing document search with statement max rows: " + statement.getMaxRows()); LOG.info( "Executing document search with statement fetch size: " + statement.getFetchSize()); perfLog = new PerformanceLogger(); final ResultSet rs = statement.executeQuery(sql); try { perfLog.log("Time to execute doc search database query.", true); final Statement searchAttributeStatement = con .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); try { return documentSearchGenerator.processResultSet(criteria, criteriaModified, searchAttributeStatement, rs, maxResultCap, fetchLimit); } finally { try { searchAttributeStatement.close(); } catch (SQLException e) { LOG.warn("Could not close search attribute statement."); } } } finally { try { rs.close(); } catch (SQLException e) { LOG.warn("Could not close result set."); } } } finally { try { statement.close(); } catch (SQLException e) { LOG.warn("Could not close statement."); } } } }); } catch (DataAccessException dae) { String errorMsg = "DataAccessException: " + dae.getMessage(); LOG.error("getList() " + errorMsg, dae); throw new RuntimeException(errorMsg, dae); } catch (Exception e) { String errorMsg = "LookupException: " + e.getMessage(); LOG.error("getList() " + errorMsg, e); throw new RuntimeException(errorMsg, e); } }
From source file:com.opensoc.enrichment.adapters.geo.GeoMysqlAdapter.java
@SuppressWarnings("unchecked") @Override/*from w ww.j av a2 s . c o m*/ public JSONObject enrich(String metadata) { ResultSet resultSet = null; try { _LOG.trace("[OpenSOC] Received metadata: " + metadata); InetAddress addr = InetAddress.getByName(metadata); if (addr.isAnyLocalAddress() || addr.isLoopbackAddress() || addr.isSiteLocalAddress() || addr.isMulticastAddress() || !ipvalidator.isValidInet4Address(metadata)) { _LOG.trace("[OpenSOC] Not a remote IP: " + metadata); _LOG.trace("[OpenSOC] Returning enrichment: " + "{}"); return new JSONObject(); } _LOG.trace("[OpenSOC] Is a valid remote IP: " + metadata); statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String locid_query = "select IPTOLOCID(\"" + metadata + "\") as ANS"; resultSet = statement.executeQuery(locid_query); if (resultSet == null) throw new Exception( "Invalid result set for metadata: " + metadata + ". Query run was: " + locid_query); resultSet.last(); int size = resultSet.getRow(); if (size == 0) throw new Exception("No result returned for: " + metadata + ". Query run was: " + locid_query); resultSet.beforeFirst(); resultSet.next(); String locid = null; locid = resultSet.getString("ANS"); if (locid == null) throw new Exception("Invalid location id for: " + metadata + ". Query run was: " + locid_query); String geo_query = "select * from location where locID = " + locid + ";"; resultSet = statement.executeQuery(geo_query); if (resultSet == null) throw new Exception("Invalid result set for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.last(); size = resultSet.getRow(); if (size == 0) throw new Exception("No result id returned for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.beforeFirst(); resultSet.next(); JSONObject jo = new JSONObject(); jo.put("locID", resultSet.getString("locID")); jo.put("country", resultSet.getString("country")); jo.put("city", resultSet.getString("city")); jo.put("postalCode", resultSet.getString("postalCode")); jo.put("latitude", resultSet.getString("latitude")); jo.put("longitude", resultSet.getString("longitude")); jo.put("dmaCode", resultSet.getString("dmaCode")); jo.put("locID", resultSet.getString("locID")); jo.put("location_point", jo.get("longitude") + "," + jo.get("latitude")); _LOG.debug("Returning enrichment: " + jo); return jo; } catch (Exception e) { e.printStackTrace(); _LOG.error("Enrichment failure: " + e); return new JSONObject(); } }
From source file:org.apache.metron.enrichment.adapters.geo.GeoMysqlAdapter.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a2s .com*/ public JSONObject enrich(String metadata) { ResultSet resultSet = null; try { _LOG.trace("[Metron] Received metadata: " + metadata); InetAddress addr = InetAddress.getByName(metadata); if (addr.isAnyLocalAddress() || addr.isLoopbackAddress() || addr.isSiteLocalAddress() || addr.isMulticastAddress() || !ipvalidator.isValidInet4Address(metadata)) { _LOG.trace("[Metron] Not a remote IP: " + metadata); _LOG.trace("[Metron] Returning enrichment: " + "{}"); return new JSONObject(); } _LOG.trace("[Metron] Is a valid remote IP: " + metadata); statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String locid_query = "select IPTOLOCID(\"" + metadata + "\") as ANS"; resultSet = statement.executeQuery(locid_query); if (resultSet == null) throw new Exception( "Invalid result set for metadata: " + metadata + ". Query run was: " + locid_query); resultSet.last(); int size = resultSet.getRow(); if (size == 0) throw new Exception("No result returned for: " + metadata + ". Query run was: " + locid_query); resultSet.beforeFirst(); resultSet.next(); String locid = null; locid = resultSet.getString("ANS"); if (locid == null) throw new Exception("Invalid location id for: " + metadata + ". Query run was: " + locid_query); String geo_query = "select * from location where locID = " + locid + ";"; resultSet = statement.executeQuery(geo_query); if (resultSet == null) throw new Exception("Invalid result set for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.last(); size = resultSet.getRow(); if (size == 0) throw new Exception("No result id returned for metadata and locid: " + metadata + ", " + locid + ". Query run was: " + geo_query); resultSet.beforeFirst(); resultSet.next(); JSONObject jo = new JSONObject(); jo.put("locID", resultSet.getString("locID")); jo.put("country", resultSet.getString("country")); jo.put("city", resultSet.getString("city")); jo.put("postalCode", resultSet.getString("postalCode")); jo.put("latitude", resultSet.getString("latitude")); jo.put("longitude", resultSet.getString("longitude")); jo.put("dmaCode", resultSet.getString("dmaCode")); jo.put("locID", resultSet.getString("locID")); jo.put("location_point", jo.get("longitude") + "," + jo.get("latitude")); _LOG.debug("Returning enrichment: " + jo); return jo; } catch (Exception e) { e.printStackTrace(); _LOG.error("Enrichment failure: " + e); return new JSONObject(); } }
From source file:org.globus.workspace.scheduler.defaults.DefaultSchedulerAdapterDB.java
/** * This moves significant prepared statement setup times to service * initialization instead of the first time they're used. * * Documentation states that PreparedStatement caches are per pool * connection but preliminary testing indicates it is effective to * just use the first one from the pool. * * @throws org.globus.workspace.persistence.WorkspaceDatabaseException exc */// w w w . j av a 2 s .c om void prepareStatements() throws WorkspaceDatabaseException { final String[] ins = DefaultSchedulerConstants.INSENSITIVE_PREPARED_STATEMENTS; final String[] pstmts = DefaultSchedulerConstants.PREPARED_STATEMENTS; Connection c = null; PreparedStatement pstmt = null; try { c = getConnection(); for (int i = 0; i < ins.length; i++) { pstmt = c.prepareStatement(ins[i], ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); pstmt.close(); } for (int i = 0; i < pstmts.length; i++) { pstmt = c.prepareStatement(pstmts[i]); pstmt.close(); } pstmt = null; } catch (SQLException e) { logger.error("", e); throw new WorkspaceDatabaseException(e); } finally { try { if (pstmt != null) { pstmt.close(); } if (c != null) { returnConnection(c); } } catch (SQLException e) { logger.error("SQLException in finally cleanup", e); } } }
From source file:com.clustercontrol.sql.util.AccessDB.java
/** * DB???//from w w w . j a va 2 s. 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; } }