Java 8 PreparedStatement - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PreparedStatement class.

This code example shows how to use the following methods:executeUpdate, setBlob, setLong, setString
Connection conn = dao.getBootstrapConn().getDBConn();
			  String st = "insert into tab_" + srcId + "(id, scn, srckey, val) values(?, ?, ?, ?)";
			  System.out.println("SQL :" + st);
			  stmt = conn.prepareStatement(st);
			  stmt.setLong(1,rId);
			  stmt.setLong(2,scn);
			  stmt.setString(3, srcKey);
			  stmt.setBlob(4, new ByteArrayInputStream(data.getBytes()));
			  stmt.executeUpdate();
		  } catch ( Exception ex) {
			  System.err.println("Exception :" + ex);
			  throw new RuntimeException(ex);
		  } finally { 
			  DBHelper.close(stmt);
		  } 
	  } 
	  @Test 
	  public void testBootstrapService() 
	              throws InstantiationException, IllegalAccessException, ClassNotFoundException, 
8
CodeRank
This code example shows how to use the following methods:setInt, setLong
    try 
    { 
      stmt =
          conn.prepareStatement("update bootstrap_loginfo set minwindowscn = ? , maxwindowscn = ? , maxrid = ? where srcid = ? and logid = ?");
 
      stmt.setLong(1, _minwindowscn);
      stmt.setLong(2, _maxwindowscn);
      stmt.setInt(3, _maxRowId);
      stmt.setInt(4, _srcid);
      stmt.setInt(5, _currlogid);
 
      stmt.executeUpdate();
      conn.commit();
    } 
    catch (SQLException e)
    { 
      LOG.error("Error occurred when saving source info to database" + e);
      throw e;
    } finally { 
    	DBHelper.close(stmt);

8
CodeRank
This code example shows how to use the following methods:execute
        ResultSet resultSet = null;
        try { 
            connection = dataSource.getConnection();
            statement = connection.prepareStatement(createTimer);
            statementParameters(timerEntity, statement);
            statement.execute();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally { 
            safeClose(resultSet);
            safeClose(statement);
            safeClose(connection);
        } 
    } 
 
 
    @Override 
    public void persistTimer(final TimerImpl timerEntity) {
        Connection connection = null;
        PreparedStatement statement = null;
8
CodeRank
This code example shows how to use the following methods:executeQuery, setString
    try 
    { 
      // Query to see if  collection type information exists for this collection type 
      stmt = con.prepareStatement("SELECT 1 FROM ALL_COLL_TYPES " +
                                      "WHERE OWNER=? AND TYPE_NAME=? AND ROWNUM < 2"); 
      stmt.setString(1, ownerName);
      stmt.setString(2, typeName);
      rs = stmt.executeQuery();
 
      // If collection information exists then it is a collection type 
      return rs.next();
    } 
    finally 
    { 
      SchemaUtils.close(rs);
      SchemaUtils.close(stmt);
    } 
  } 
 
  public CollectionTypeInfo buildCollectionTypeInfo(Connection con,
                                                    String ownerName,
8
CodeRank
This code example shows how to use the following methods:executeQuery
		ResultSet rs = null;
		long numRecords = -1;
		try 
		{ 
			stmt = _conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			if (rs.next())
			{ 
				numRecords = rs.getLong(1);
			} 
		} catch ( SQLException sqlEx) {
		    LOG.error("getNumRecords() error: " + sqlEx.getMessage(), sqlEx);
		} finally { 
			DBHelper.close(rs,stmt,null);
		} 
		return numRecords;
	} 
 
  /** 
   * 
8
CodeRank
This code example shows how to use the following methods:executeUpdate, setInt, setString, close
    } 
 
    private void addFlag(Connection connection, int newFlagId, String description, int lookupId) throws SQLException {
        PreparedStatement statement = connection.prepareStatement("insert into account_state_flag("
                + "  flag_id,lookup_id,status_id,flag_description,retain_flag)" + "values(?,?,?,?,?)"); 
        statement.setInt(1, newFlagId);
        statement.setInt(2, lookupId);
        statement.setInt(3, STATUS_10);
        statement.setString(4, description);
        boolean retain = false;
        statement.setInt(5, retain ? 1 : 0);
        statement.executeUpdate();
        statement.close();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:setString
    try 
    { 
      // Query to see if  user attribute information exists for this user type 
      stmt = con.prepareStatement("SELECT 1 FROM ALL_TYPE_ATTRS " +
                                    "WHERE OWNER=? AND TYPE_NAME=? AND ROWNUM < 2"); 
      stmt.setString(1, ownerName);
      stmt.setString(2, typeName);
      rs = stmt.executeQuery();
 
      // If a row exists then this is a user type 
      return rs.next();
    } 
    finally 
    { 
      SchemaUtils.close(rs);
      SchemaUtils.close(stmt);
    } 
  } 
 
  public UserTypeInfo buildUserTypeInfo(Connection con, String typeOwner, String typeName)
      throws SQLException 
7
CodeRank
This code example shows how to use the following methods:setString
 
        Connection con = null;
        try { 
            con = DBUtils.getConn();
            PreparedStatement stmt = con.prepareStatement("insert into users (first_nm, last_nm, email, username, user_type, password) values (?,?,?,?,?,?)");
            stmt.setString(1, user.getFirstNm());
            stmt.setString(2, user.getLastNm());
            stmt.setString(3, user.getEmail());
            stmt.setString(4, user.getUsername());
            stmt.setString(5, user.getUserType());
            stmt.setString(6, EncryptionUtil.hash(user.getPassword()));
            stmt.execute();
            DBUtils.closeStmt(stmt);
 
        } catch (Exception e) {
            e.printStackTrace();
        } 
        DBUtils.closeConn(con);
 
    } 
7
CodeRank
This code example shows how to use the following methods:executeUpdate, setInt, close
    } 
 
    private void addAction(Connection connection, int actionId, int lookupId) throws SQLException {
        PreparedStatement statement = connection
                .prepareStatement("insert into account_action(account_action_id,lookup_id) values (?,?)");
        statement.setInt(1, actionId);
        statement.setInt(2, lookupId);
        statement.executeUpdate();
        statement.close();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:executeUpdate, setString, close, getGeneratedKeys
    protected int addLookupEntity(Connection connection, String name, String description)  throws SQLException {
       int newId = -1;
       PreparedStatement statement = connection.prepareStatement(
               "insert into lookup_entity(entity_id,entity_name,description) values(null,?,?)", 
                PreparedStatement.RETURN_GENERATED_KEYS);
       statement.setString(1, name);
       statement.setString(2, description);
       statement.executeUpdate();
       ResultSet keys = statement.getGeneratedKeys();
       keys.next();
       newId = Integer.parseInt(keys.getString(1));
       statement.close();
       return newId;
    } 
 
 
    public void setUpgradeContext(ApplicationContext upgradeContext) {
        this.upgradeContext = upgradeContext;
    } 
 
7
CodeRank

Related Java 8 PreparedStatement Questions & Answers:

See Code Examples for Java 8 PreparedStatement Methods: