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:pack1.test.java
@WebMethod(operationName = "convert") public String convert(@WebParam(name = "encodedImageStr") String encodedImageStr, @WebParam(name = "fileName") String fileName, @WebParam(name = "AOR") String AOR, @WebParam(name = "val") int value) { System.out.println("Value" + value); FileOutputStream imageOutFile = null; try {//from w ww . j a v a 2 s . co m Connection con, con1; Statement stmtnew = null; area = Double.parseDouble(AOR); //int val=Integer.parseInt(value); System.out.println("connecting"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("connected"); con = DriverManager.getConnection("jdbc:odbc:test"); System.out.println(" driver loaded in connection.jsp"); stmtnew = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); // Decode String using Base64 Class byte[] imageByteArray = encodedImageStr.getBytes(); // Write Image into File system - Make sure you update the path imageOutFile = new FileOutputStream( "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/cropped" + fileName); imageOutFile.write(imageByteArray); imageOutFile.close(); System.out.println("Image Successfully Stored"); FileInputStream leafPicPath = new FileInputStream( "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/cropped" + fileName); BufferedImage cat; int height, width; cat = ImageIO.read(leafPicPath); height = cat.getHeight(); width = cat.getWidth(); for (int w = 0; w < cat.getWidth(); w++) { for (int h = 0; h < cat.getHeight(); h++) { // BufferedImage.getRGB() saves the colour of the pixel as a single integer. // use Color(int) to grab the RGB values individually. Color color = new Color(cat.getRGB(w, h)); // use the RGB values to get their average. int averageColor = ((color.getRed() + color.getGreen() + color.getBlue()) / 3); // create a new Color object using the average colour as the red, green and blue // colour values Color avg = new Color(averageColor, averageColor, averageColor); // set the pixel at that position to the new Color object using Color.getRGB(). cat.setRGB(w, h, avg.getRGB()); } } String greyPicPath = "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/greyscale" + fileName; greyPicPath = greyPicPath.trim(); File outputfile = new File(greyPicPath); ImageIO.write(cat, "jpg", outputfile); System.out.println("Image is successfully converted to grayscale"); String binPicPath = "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/binary" + fileName; File f2 = new File(binPicPath); System.out.println("1"); ImageProcessor ip; ImagePlus imp = new ImagePlus(greyPicPath); System.out.println("2"); ip = imp.getProcessor(); ip.invertLut(); ip.autoThreshold(); System.out.println("3"); BufferedImage bf = ip.getBufferedImage(); System.out.println("4"); ImageIO.write(bf, "jpg", f2); System.out.println("Image is successfully converted to binary image"); if (choice == 1) { String Inserted1 = "insert into test (PhyAOR) values ('" + area + "')"; System.out.println("InsertedQuery" + Inserted1); stmtnew.executeUpdate(Inserted1); Statement stmt = con.createStatement(); ResultSet rs = null; String ID = "select MAX(id) as id from test"; System.out.println("Query" + ID); rs = stmt.executeQuery(ID); while (rs.next()) { id = rs.getInt("id"); } String Inserted2 = "update test set fileName0=? where id=?"; PreparedStatement ps = con.prepareStatement(Inserted2); ps.setString(1, fileName); ps.setDouble(2, id); int rt = ps.executeUpdate(); choice++; } System.out.println(choice); if (value == 1) { int count = countblackpixel(binPicPath); calculatepixA(count, area); //returnVal=value+"/"+count+"/"+OnepixArea; } else if (value == 2) { int flag = countblackpixel(binPicPath); // calculatepixA(flag, area); leafarea0(flag, area); //returnVal=value+"/"+flag+"/"+OnepixArea+"/"+leafArea0; //System.out.println(returnVal); } else if (value == 3) { String Inserted3 = "update test set fileName180=? where id=?"; PreparedStatement ps1 = con.prepareStatement(Inserted3); ps1.setString(1, fileName); ps1.setDouble(2, id); int rt = ps1.executeUpdate(); int black = countblackpixel(binPicPath); leafarea180(area, black); finalarea(); Statement stmt = con.createStatement(); ResultSet rs = null; String finalans = "select PhyAOR,onePixA,leafarea0,leafarea180,finalleafarea from test where id=" + id + ""; rs = stmt.executeQuery(finalans); while (rs.next()) { returnVal = rs.getString("PhyAOR") + "/" + rs.getString("onePixA") + "/" + rs.getString("leafarea0") + "/" + rs.getString("leafarea180") + "/" + rs.getString("finalleafarea"); } //returnVal=value+"/"+black+"/"+OnepixArea+"/"+leafArea180+"/"+Leaf_Area; } else if (value == 4) { finalarea(); } imageOutFile.close(); } catch (Exception ex) { Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); System.out.println(ex); } return returnVal; }
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>(); }// ww w.j ava 2 s . c o m 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:DbManager.java
/** * Initialize the DbManager, using hsqldb defaults. *//*ww w . j a v a 2 s .c om*/ public DbManager() { dbArray = false; try { initDb("hsqldb", ".", "sa", ""); stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.wso2.authenticator.jdbc.JDBCAuthenticator.java
/** * @see org.wso2.usermanager.Authenticator#authenticate(String, Object) *//*from www .j a v a 2s . com*/ public boolean authenticate(String userName, Object credentials) throws AuthenticatorException { if (credentials == null) { return false; } if (userName == null) { return false; } boolean bValue = false; if (!(credentials instanceof String)) { throw new AuthenticatorException("Can handle only string type credentials"); } else { try { this.open(); String password = (String) credentials; String stmtValue = this.constructSQLtoReadPassword(userName); if (log.isDebugEnabled()) { log.debug(stmtValue); } Statement stmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(stmtValue); if (rs.first() == true) { String value = rs.getString(userCredentialColumn); if ((value != null) && (value.equals(password))) { bValue = true; } } } catch (SQLException e) { log.error(e.getMessage(), e); throw new AuthenticatorException("exceptionOnAuthenticate"); } } return bValue; }
From source file:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson5a.java
protected AttackResult injectableQuery(String accountName) { try {/*from ww w . j a v a2 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(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 {//from w ww .ja va 2 s . co m 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 {// ww 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 w w w . j a v a 2 s .c o 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(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 {/*from w w w . j a v a2s . co 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); }
From source file:de.static_interface.reallifeplugin.database.AbstractTable.java
public ResultSet executeQuery(String sql, @Nullable Object... paramObjects) throws SQLException { sql = sql.replaceAll("\\Q{TABLE}\\E", getName()); try {/*from w w w .j a va 2 s . c o m*/ PreparedStatement statment = db.getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); if (paramObjects != null) { int i = 1; for (Object s : paramObjects) { statment.setObject(i, s); i++; } } return statment.executeQuery(); } catch (SQLException e) { ReallifeMain.getInstance().getLogger() .severe("Couldn't execute SQL query: " + sqlToString(sql, paramObjects)); throw e; } }