Code example for PreparedStatement

Methods: executeQuery, setString

0
                             "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 { 
            DBUtils.closeAllConnections(prepStmt, null, rs);
        } 
        return id;
    }