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.itdaoshi.discuz.dao.CdbUcMembersDAObject.java
protected synchronized Object insertDB(Object obj1) { PreparedStatement preStat = null; StringBuffer sqlStat = new StringBuffer(); CdbUcMembers obj = (CdbUcMembers) obj1; synchronized (conn) { try {/*from ww w . j a v a 2 s.c o m*/ Long nextID = getNextPrimaryID(); // Integer nextID = 2; sqlStat.append("INSERT "); sqlStat.append( "INTO CDB_UC_MEMBERS(uid, username, password, email, myid, myidkey, regip, regdate, lastloginip, lastlogintime, salt, secques) "); sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); preStat = conn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); setPrepareStatement(preStat, 1, nextID); setPrepareStatement(preStat, 2, obj.getUsername()); setPrepareStatement(preStat, 3, obj.getPassword()); setPrepareStatement(preStat, 4, obj.getEmail()); setPrepareStatement(preStat, 5, obj.getMyid()); setPrepareStatement(preStat, 6, obj.getMyidkey()); setPrepareStatement(preStat, 7, obj.getRegip()); setPrepareStatement(preStat, 8, obj.getRegdate()); setPrepareStatement(preStat, 9, obj.getLastloginip()); setPrepareStatement(preStat, 10, obj.getLastlogintime()); setPrepareStatement(preStat, 11, obj.getSalt()); setPrepareStatement(preStat, 12, obj.getSecques()); preStat.executeUpdate(); return obj; } catch (Exception Ex) { Ex.printStackTrace(); } finally { try { preStat.close(); } catch (Exception ignore) { } finally { preStat = null; } } } return obj; }
From source file:com.cloudera.sqoop.manager.MySQLCompatTest.java
@Override protected void dropTableIfExists(String table) throws SQLException { Connection conn = getManager().getConnection(); PreparedStatement statement = conn.prepareStatement("DROP TABLE IF EXISTS " + table, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); try {//from ww w.j a v a 2 s. c o m statement.executeUpdate(); conn.commit(); } finally { statement.close(); } }
From source file:com.itdaoshi.dokeos.dao.UserDAObject.java
protected synchronized User insert(User obj) { PreparedStatement preStat = null; StringBuffer sqlStat = new StringBuffer(); synchronized (conn) { try {//from w w w .ja v a 2 s.co m Long nextID = getNextPrimaryID(); sqlStat.append("INSERT "); sqlStat.append( "INTO USER(user_id, lastname, firstname, username, password, auth_source, email, status, official_code, phone, picture_uri, creator_id, competences, diplomas, openarea, teach, productions, chatcall_user_id, chatcall_date, chatcall_text, language, registration_date, expiration_date, active, openid, theme, hr_dept_id) "); sqlStat.append( "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); preStat = conn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); setPrepareStatement(preStat, 1, nextID); setPrepareStatement(preStat, 2, obj.getLastname()); setPrepareStatement(preStat, 3, obj.getFirstname()); setPrepareStatement(preStat, 4, obj.getUsername()); setPrepareStatement(preStat, 5, obj.getPassword()); setPrepareStatement(preStat, 6, obj.getAuthSource()); setPrepareStatement(preStat, 7, obj.getEmail()); setPrepareStatement(preStat, 8, obj.getStatus()); setPrepareStatement(preStat, 9, obj.getOfficialCode()); setPrepareStatement(preStat, 10, obj.getPhone()); setPrepareStatement(preStat, 11, obj.getPictureUri()); setPrepareStatement(preStat, 12, obj.getCreatorID()); setPrepareStatement(preStat, 13, obj.getCompetences()); setPrepareStatement(preStat, 14, obj.getDiplomas()); setPrepareStatement(preStat, 15, obj.getOpenarea()); setPrepareStatement(preStat, 16, obj.getTeach()); setPrepareStatement(preStat, 17, obj.getProductions()); setPrepareStatement(preStat, 18, obj.getChatcallUserID()); setPrepareStatement(preStat, 19, obj.getChatcallDate()); setPrepareStatement(preStat, 20, obj.getChatcallText()); setPrepareStatement(preStat, 21, obj.getLanguage()); setPrepareStatement(preStat, 22, obj.getRegistrationDate()); setPrepareStatement(preStat, 23, obj.getExpirationDate()); setPrepareStatement(preStat, 24, obj.getActive()); setPrepareStatement(preStat, 25, obj.getOpenid()); setPrepareStatement(preStat, 26, obj.getTheme()); setPrepareStatement(preStat, 27, obj.getHrDeptID()); preStat.executeUpdate(); return obj; } catch (Exception Ex) { Ex.printStackTrace(); } finally { try { preStat.close(); } catch (Exception ignore) { } finally { preStat = null; } } } return obj; }
From source file:org.syncope.core.init.ContentLoader.java
@Transactional public void load() { // 0. DB connection, to be used below Connection conn = DataSourceUtils.getConnection(dataSource); // 1. Check wether we are allowed to load default content into the DB Statement statement = null;// w ww . j a v a 2 s . c om ResultSet resultSet = null; boolean existingData = false; try { statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); resultSet = statement.executeQuery("SELECT * FROM " + SyncopeConf.class.getSimpleName()); resultSet.last(); existingData = resultSet.getRow() > 0; } catch (SQLException e) { LOG.error("Could not access to table " + SyncopeConf.class.getSimpleName(), e); // Setting this to true make nothing to be done below existingData = true; } finally { try { if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { LOG.error("While closing SQL result set", e); } try { if (statement != null) { statement.close(); } } catch (SQLException e) { LOG.error("While closing SQL statement", e); } } if (existingData) { LOG.info("Data found in the database, leaving untouched"); return; } LOG.info("Empty database found, loading default content"); // 2. Create views LOG.debug("Creating views"); try { InputStream viewsStream = getClass().getResourceAsStream("/views.xml"); Properties views = new Properties(); views.loadFromXML(viewsStream); for (String idx : views.stringPropertyNames()) { LOG.debug("Creating view {}", views.get(idx).toString()); try { statement = conn.createStatement(); statement.executeUpdate(views.get(idx).toString().replaceAll("\\n", " ")); statement.close(); } catch (SQLException e) { LOG.error("Could not create view ", e); } } LOG.debug("Views created, go for indexes"); } catch (Throwable t) { LOG.error("While creating views", t); } // 3. Create indexes LOG.debug("Creating indexes"); try { InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml"); Properties indexes = new Properties(); indexes.loadFromXML(indexesStream); for (String idx : indexes.stringPropertyNames()) { LOG.debug("Creating index {}", indexes.get(idx).toString()); try { statement = conn.createStatement(); statement.executeUpdate(indexes.get(idx).toString()); statement.close(); } catch (SQLException e) { LOG.error("Could not create index ", e); } } LOG.debug("Indexes created, go for default content"); } catch (Throwable t) { LOG.error("While creating indexes", t); } finally { DataSourceUtils.releaseConnection(conn, dataSource); } try { conn.close(); } catch (SQLException e) { LOG.error("While closing SQL connection", e); } // 4. Load default content SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); parser.parse(getClass().getResourceAsStream("/content.xml"), importExport); LOG.debug("Default content successfully loaded"); } catch (Throwable t) { LOG.error("While loading default content", t); } }
From source file:com.itemanalysis.jmetrik.stats.irt.linking.DbThetaDistribution.java
public DistributionApproximation getDistribution(Connection conn, DataTableName tableName, VariableName thetaName, VariableName weightName, boolean hasWeight) throws SQLException { points = new ArrayList<Double>(); Min min = new Min(); Max max = new Max(); Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery query = new SelectQuery(); query.addColumn(sqlTable, thetaName.nameForDatabase()); if (hasWeight) { query.addColumn(sqlTable, weightName.nameForDatabase()); weights = new ArrayList<Double>(); }/*w w w. jav a 2 s.c om*/ Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(query.toString()); double value = 0.0; double w = 1.0; while (rs.next()) { value = rs.getDouble(thetaName.nameForDatabase()); if (!rs.wasNull()) { if (hasWeight) { w = rs.getDouble(weightName.nameForDatabase()); if (rs.wasNull()) { w = 0.0; } points.add(value); weights.add(w); min.increment(value); max.increment(value); } else { points.add(value); min.increment(value); max.increment(value); } } } rs.close(); stmt.close(); ContinuousDistributionApproximation dist = new ContinuousDistributionApproximation(points.size(), min.getResult(), max.getResult()); if (hasWeight) { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); dist.setDensityAt(i, weights.get(i)); } } else { for (int i = 0; i < points.size(); i++) { dist.setPointAt(i, points.get(i)); } } return dist; }
From source file:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson5a.java
protected AttackResult injectableQuery(String accountName) { try {/*from www . j ava 2s . 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())) { 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(success().feedback("sql-injection.5a.success") .feedbackArgs(output.toString()).build()); } else { return trackProgress(failed().output(output.toString()).build()); } } else { return trackProgress(failed().feedback("sql-injection.5a.no.results").build()); } } catch (SQLException sqle) { return trackProgress(failed().output(sqle.getMessage()).build()); } } catch (Exception e) { return trackProgress(failed().output(this.getClass().getName() + " : " + e.getMessage()).build()); } }
From source file:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson5b.java
protected AttackResult injectableQuery(String accountName) { try {// w ww. j a v a 2s .c om Connection connection = DatabaseUtilities.getConnection(getWebSession()); String query = "SELECT * FROM user_data WHERE userid = " + 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(SqlInjectionLesson5a.writeTable(results, resultsMetaData)); results.last(); // If they get back more than one user they succeeded if (results.getRow() >= 6) { return trackProgress(success().feedback("sql-injection.5b.success") .feedbackArgs(output.toString()).build()); } else { return trackProgress(failed().output(output.toString()).build()); } } else { return trackProgress(failed().feedback("sql-injection.5b.no.results").build()); // output.append(getLabelManager().get("NoResultsMatched")); } } catch (SQLException sqle) { return trackProgress(failed().output(sqle.getMessage()).build()); } } catch (Exception e) { e.printStackTrace(); return trackProgress(failed().output(this.getClass().getName() + " : " + e.getMessage()).build()); } }
From source file:org.owasp.webgoat.plugin.CrossSiteScriptingLesson5b.java
protected AttackResult injectableQuery(String accountName) { try {//w w w. ja v a 2 s.com Connection connection = DatabaseUtilities.getConnection(getWebSession()); String query = "SELECT * FROM user_data WHERE userid = " + 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. ")); // output.append(getLabelManager().get("NoResultsMatched")); } } 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:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson6a.java
protected AttackResult injectableQuery(String accountName) { try {/*from ww w . j a v a 2 s. c om*/ 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())) { ResultSetMetaData resultsMetaData = results.getMetaData(); StringBuffer output = new StringBuffer(); output.append(SqlInjectionLesson5a.writeTable(results, resultsMetaData)); results.last(); // If they get back more than one user they succeeded if (results.getRow() >= 5) { return trackProgress(success().feedback("sql-injection.6a.success") .feedbackArgs(output.toString()).build()); } else { return trackProgress(failed().output(output.toString()).build()); } } else { return trackProgress(failed().feedback("sql-injection.6a.no.results").build()); } } catch (SQLException sqle) { return trackProgress(failed().output(sqle.getMessage()).build()); } } catch (Exception e) { e.printStackTrace(); return trackProgress(failed().output(this.getClass().getName() + " : " + e.getMessage()).build()); } }
From source file:org.owasp.webgoat.plugin.CrossSiteScriptingLesson6b.java
protected String getPassword() { String password = "dave"; try {/*w ww .j a va2 s .c o m*/ Connection connection = DatabaseUtilities.getConnection(getWebSession()); String query = "SELECT password FROM user_system_data WHERE user_name = 'dave'"; try { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet results = statement.executeQuery(query); if ((results != null) && (results.first() == true)) { password = results.getString("password"); } } catch (SQLException sqle) { sqle.printStackTrace(); // do nothing } } catch (Exception e) { e.printStackTrace(); // do nothing } return (password); }