PreparedStatement setString - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PreparedStatement setString method.

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: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: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, 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
This code example shows how to use the following methods:executeQuery, setString
			con = DataAccess.getConnection();
 
			ps = con.prepareStatement(
				"select classNameId from ClassName_ where value = ?"); 
 
			ps.setString(1, className);
 
			rs = ps.executeQuery();
 
			if (rs.next()) {
				return rs.getLong("classNameId");
			} 
 
			return 0; 
		} 
		finally { 
			DataAccess.cleanUp(con, ps, rs);
		} 
	} 
 

7
CodeRank
This code example shows how to use the following methods:executeQuery, setString
 
			ps = con.prepareStatement(
				"select bitwiseValue from ResourceAction where name = ? and " + 
					"actionId = ?"); 
 
			ps.setString(1, name);
			ps.setString(2, actionId);
 
			rs = ps.executeQuery();
 
			if (rs.next()) {
				return rs.getLong("bitwiseValue");
			} 
 
			return 0; 
		} 
		finally { 
			DataAccess.cleanUp(con, ps, rs);
		} 
	} 

7
CodeRank
This code example shows how to use the following methods:setString
                             "AND API.API_NAME = ?" + 
                             "AND API.API_VERSION = ?"; 
 
        try { 
            prepStmt = connection.prepareStatement(getAPIQuery);
            prepStmt.setString(1, apiId.getProviderName());
            prepStmt.setString(2, apiId.getApiName());
            prepStmt.setString(3, apiId.getVersion());
            rs = prepStmt.executeQuery();
            if (rs.next()) {
                id = rs.getInt("API_ID");
            } 
            if (id == -1) {
                String msg = "Unable to find the API: " + apiId + " in the database";
                System.out.println(msg);
                throw new APIManagementException(msg);
            } 
        } catch (SQLException e) {
            e.printStackTrace();
        } finally { 
7
CodeRank
This code example shows how to use the following methods:execute, setLong, setString
 
        Connection con = null;
        try { 
            con = DBUtils.getConn();
            PreparedStatement stmt = con.prepareStatement("insert into scripts (display_nm, script, user_id) values (?,?,?)");
            stmt.setString(1, script.getDisplayNm());
            stmt.setString(2, script.getScript());
            stmt.setLong(3, userId);
            stmt.execute();
            DBUtils.closeStmt(stmt);
 
        } catch (Exception e) {
            e.printStackTrace();
        } 
        DBUtils.closeConn(con);
 
    } 
 
    /** 
     * updates existing script 
7
CodeRank

Related PreparedStatement setString Questions & Answers:

setString Method Overview
Sets the designated parameter to the given Java String value.
See Code Examples for other Java 8 PreparedStatement Methods: