List of usage examples for java.sql ResultSet CONCUR_UPDATABLE
int CONCUR_UPDATABLE
To view the source code for java.sql ResultSet CONCUR_UPDATABLE.
Click Source Link
ResultSet
object that may be updated. From source file:org.biblionum.ouvrage.modele.CategorieOuvrageModele.java
/** * Java method that updates a row in the generated sql table * * @param con (open java.sql.Connection) * @param designation_categorie//from w w w . j av a 2 s . c om * @return boolean (true on success) * @throws SQLException */ public static boolean updateCategorieouvrage(DataSource ds, int keyId, String designation_categorie) throws SQLException { con = ds.getConnection(); String sql = "SELECT * FROM categorieouvrage WHERE id = ?"; PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); statement.setInt(1, keyId); ResultSet entry = statement.executeQuery(); entry.last(); int rows = entry.getRow(); entry.beforeFirst(); if (rows == 0) { entry.close(); statement.close(); con.close(); return false; } entry.next(); if (designation_categorie != null) { entry.updateString("designation_categorie", designation_categorie); } entry.updateRow(); entry.close(); statement.close(); con.close(); return true; }
From source file:de.static_interface.reallifeplugin.database.AbstractTable.java
public T[] get(String query, Object... paramObjects) throws SQLException { query = query.replaceAll("\\Q{TABLE}\\E", getName()); PreparedStatement statement = db.getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); if (paramObjects != null && paramObjects.length > 0) { int i = 1; for (Object s : paramObjects) { statement.setObject(i, s);/*from w ww.j a va 2s . co m*/ i++; } } return deserialize(statement.executeQuery()); }
From source file:DbManager.java
/** * Initialize a generic DbManager./*from w ww .ja v a 2 s. co m*/ * * @param driver * the driver. * @param database * the database name. * @param login * the login. * @param passwd * the password. */ public DbManager(String driver, String database, String login, String passwd) { dbArray = false; try { initDb(driver, database, login, passwd); stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); } catch (Exception e) { e.printStackTrace(); } }
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 w w. ja v a2 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:org.zanata.liquibase.custom.MigrateHTermCommentToString.java
@Override public void execute(Database database) throws CustomChangeException { final JdbcConnection conn = (JdbcConnection) database.getConnection(); try (Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { Map<Long, String> termCommentsMap = new HashMap<Long, String>(); ResultSet rs1 = null;//from w w w. j a v a 2s .c om ResultSet rs2 = null; try { String termCommentsSql = "select term.id, comment.comment from " + "HGlossaryTerm as term, HTermComment as comment where comment.glossaryTermId = term.id"; rs1 = stmt.executeQuery(termCommentsSql); while (rs1.next()) { long termId = rs1.getLong(1); String comment = rs1.getString(2); String newComment = null; if (termCommentsMap.containsKey(termId)) { newComment = joinComment(termCommentsMap.get(termId), comment); } else { newComment = joinComment(null, comment); } termCommentsMap.put(termId, newComment); } String termSql = "select term.id, term.comment from HGlossaryTerm term"; rs2 = stmt.executeQuery(termSql); while (rs2.next()) { long termId = rs2.getLong(1); String comment = termCommentsMap.get(termId); rs2.updateString(2, comment); rs2.updateRow(); } } finally { rs1.close(); rs2.close(); } } catch (SQLException | DatabaseException e) { throw new CustomChangeException(e); } }
From source file:org.biblionum.ouvrage.modele.OuvrageTypeModele.java
/** * Java method that updates a row in the generated sql table * * @param con (open java.sql.Connection) * @param designation_typeou//from w w w .j a v a 2 s. c om * @return boolean (true on success) * @throws SQLException */ public boolean updateOuvragetype(DataSource ds, int keyId, String designation_typeou) throws SQLException { con = ds.getConnection(); String sql = "SELECT * FROM ouvragetype WHERE id = ?"; PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); statement.setInt(1, keyId); ResultSet entry = statement.executeQuery(); entry.last(); int rows = entry.getRow(); entry.beforeFirst(); if (rows == 0) { entry.close(); statement.close(); con.close(); return false; } entry.next(); if (designation_typeou != null) { entry.updateString("designation_typeou", designation_typeou); } entry.updateRow(); entry.close(); statement.close(); con.close(); return true; }
From source file:DbManager.java
/** * Initialize the DbManager, using hsqldb defaults. *///from w w w . ja v a2 s .c o m 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:net.pms.database.TableThumbnails.java
/** * Attempts to find a thumbnail in this table by MD5 hash. If not found, * it writes the new thumbnail to this table. * Finally, it writes the ID from this table as the THUMBID in the FILES * table.//from w w w. java 2s. c om * * @param thumbnail * @param fullPathToFile */ public static void setThumbnail(final DLNAThumbnail thumbnail, final String fullPathToFile) { String query; String md5Hash = DigestUtils.md5Hex(thumbnail.getBytes(false)); try (Connection connection = database.getConnection()) { query = "SELECT * FROM " + TABLE_NAME + " WHERE MD5 = " + sqlQuote(md5Hash) + " LIMIT 1"; LOGGER.trace("Searching for thumbnail in {} with \"{}\" before update", TABLE_NAME, query); TABLE_LOCK.writeLock().lock(); try (PreparedStatement statement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, Statement.RETURN_GENERATED_KEYS)) { connection.setAutoCommit(false); try (ResultSet result = statement.executeQuery()) { if (result.next()) { LOGGER.trace( "Found existing file entry with ID {} in {}, setting the THUMBID in the FILES table", result.getInt("ID"), TABLE_NAME); // Write the existing thumbnail ID to the FILES table PMS.get().getDatabase().updateThumbnailId(fullPathToFile, result.getInt("ID")); } else { LOGGER.trace("File entry \"{}\" not found in {}", md5Hash, TABLE_NAME); result.moveToInsertRow(); result.updateString("MD5", md5Hash); result.updateObject("THUMBNAIL", thumbnail); result.updateTimestamp("MODIFIED", new Timestamp(System.currentTimeMillis())); result.insertRow(); try (ResultSet generatedKeys = statement.getGeneratedKeys()) { if (generatedKeys.next()) { // Write the new thumbnail ID to the FILES table LOGGER.trace( "Inserting new thumbnail with ID {}, setting the THUMBID in the FILES table", generatedKeys.getInt(1)); PMS.get().getDatabase().updateThumbnailId(fullPathToFile, generatedKeys.getInt(1)); } } } } finally { connection.commit(); } } finally { TABLE_LOCK.writeLock().unlock(); } } catch (SQLException e) { LOGGER.error("Database error while writing \"{}\" to {}: {}", md5Hash, TABLE_NAME, e.getMessage()); LOGGER.trace("", e); } }
From source file:org.wso2.authenticator.jdbc.JDBCAuthenticator.java
/** * @see org.wso2.usermanager.Authenticator#authenticate(String, Object) *//*from w w w. j a v a 2 s .c o m*/ 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: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 ww . jav a 2 s.c om*/ 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; } }