Example usage for java.sql ResultSet getInt

List of usage examples for java.sql ResultSet getInt

Introduction

In this page you can find the example usage for java.sql ResultSet getInt.

Prototype

int getInt(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language.

Usage

From source file:com.app.dao.SearchQueryDAO.java

private static SearchQuery _createSearchQueryFromResultSet(ResultSet resultSet) throws SQLException {

    SearchQuery searchQuery = new SearchQuery();

    searchQuery.setSearchQueryId(resultSet.getInt("searchQueryId"));
    searchQuery.setUserId(resultSet.getInt("userId"));
    searchQuery.setKeywords(resultSet.getString("keywords"));
    searchQuery.setCategoryId(resultSet.getString("categoryId"));
    searchQuery.setSubcategoryId(resultSet.getString("subcategoryId"));
    searchQuery.setSearchDescription(resultSet.getBoolean("searchDescription"));
    searchQuery.setFreeShippingOnly(resultSet.getBoolean("freeShippingOnly"));
    searchQuery.setNewCondition(resultSet.getBoolean("newCondition"));
    searchQuery.setUsedCondition(resultSet.getBoolean("usedCondition"));
    searchQuery.setUnspecifiedCondition(resultSet.getBoolean("unspecifiedCondition"));
    searchQuery.setAuctionListing(resultSet.getBoolean("auctionListing"));
    searchQuery.setFixedPriceListing(resultSet.getBoolean("fixedPriceListing"));
    searchQuery.setMaxPrice(resultSet.getDouble("maxPrice"));
    searchQuery.setMinPrice(resultSet.getDouble("minPrice"));
    searchQuery.setGlobalId(resultSet.getString("globalId"));
    searchQuery.setActive(resultSet.getBoolean("active"));

    return searchQuery;
}

From source file:com.app.dao.CategoryDAO.java

private static Category _createCategoryFromResultSet(ResultSet resultSet) throws SQLException {

    Category category = new Category();

    category.setCategoryId(resultSet.getString("categoryId"));
    category.setCategoryName(resultSet.getString("categoryName"));
    category.setCategoryParentId(resultSet.getString("categoryParentId"));
    category.setCategoryLevel(resultSet.getInt("categoryLevel"));

    return category;
}

From source file:com.nabla.wapp.report.server.ReportManager.java

protected static Integer getRole(final Connection conn, final String name) throws SQLException {
    if (name != null) {
        final PreparedStatement stmt = StatementFormat.prepare(conn,
                "SELECT id FROM role WHERE name LIKE ? AND uname IS NOT NULL;", name);
        try {// www  . j  a va  2s .  c  o  m
            final ResultSet rs = stmt.executeQuery();
            try {
                if (rs.next())
                    return rs.getInt(1);
            } finally {
                rs.close();
            }
        } finally {
            stmt.close();
        }
    }
    return null;
}

From source file:de.dakror.virtualhub.server.DBManager.java

public static Eticet eticet(File f, String catalog, Eticet e) {
    try {// w  ww  . j  a va 2 s  .c  om
        if (e == Eticet.NULL) {
            ResultSet rs = connection.createStatement()
                    .executeQuery("SELECT ETICET FROM ETICETS WHERE PATH = \"" + f.getPath().replace("\\", "/")
                            + "\" AND CATALOG = \"" + catalog + "\"");
            if (!rs.next())
                return Eticet.NONE;

            return Eticet.values()[rs.getInt(1)];
        } else {
            if (e == Eticet.NONE)
                connection.createStatement().executeUpdate("DELETE FROM ETICETS WHERE PATH = \""
                        + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\"");
            else
                connection.createStatement().executeUpdate(
                        "INSERT OR REPLACE INTO ETICETS VALUES(\"" + f.getPath().replace("\\", "/") + "\","
                                + e.ordinal() + ") AND CATALOG = \"" + catalog + "\"");
        }
    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    return null;
}

From source file:com.nabla.dc.server.handler.fixed_asset.Asset.java

static public <P> boolean validateDepreciationPeriod(final Connection conn, final IAssetRecord asset,
        @Nullable final P pos, final IErrorList<P> errors) throws SQLException, DispatchException {
    final PreparedStatement stmt = StatementFormat.prepare(conn,
            "SELECT t.min_depreciation_period, t.max_depreciation_period"
                    + " FROM fa_asset_category AS t INNER JOIN fa_company_asset_category AS r ON r.fa_asset_category_id=t.id"
                    + " WHERE r.id=?;",
            asset.getCompanyAssetCategoryId());
    try {//from   ww  w .  j  a  va2s . c o  m
        final ResultSet rs = stmt.executeQuery();
        try {
            if (!rs.next()) {
                errors.add(pos, asset.getCategoryField(), ServerErrors.UNDEFINED_ASSET_CATEGORY_FOR_COMPANY);
                return false;
            }
            if (rs.getInt("min_depreciation_period") > asset.getDepreciationPeriod()
                    || rs.getInt("max_depreciation_period") < asset.getDepreciationPeriod()) {
                errors.add(pos, asset.getDepreciationPeriodField(), CommonServerErrors.INVALID_VALUE);
                return false;
            }
        } finally {
            rs.close();
        }
    } finally {
        stmt.close();
    }
    return true;
}

From source file:org.red5.webapps.admin.controllers.service.UserDAO.java

public static AdminUserDetails getUser(String username) {
    AdminUserDetails details = null;//from   w  w  w .ja v  a2s  .  c o  m
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = UserDatabase.getConnection();
        //make a statement
        stmt = conn.prepareStatement("SELECT * FROM APPUSER WHERE username = ?");
        stmt.setString(1, username);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            log.debug("User found");
            details = new AdminUserDetails();
            details.setEnabled("enabled".equals(rs.getString("enabled")));
            details.setPassword(rs.getString("password"));
            details.setUserid(rs.getInt("userid"));
            details.setUsername(rs.getString("username"));
            //
            rs.close();
            //get role            
            stmt = conn.prepareStatement("SELECT authority FROM APPROLE WHERE username = ?");
            stmt.setString(1, username);
            rs = stmt.executeQuery();
            if (rs.next()) {
                GrantedAuthority[] authorities = new GrantedAuthority[1];
                authorities[0] = new GrantedAuthorityImpl(rs.getString("authority"));
                details.setAuthorities(authorities);
                //
                //if (daoAuthenticationProvider != null) {
                //User usr = new User(username, details.getPassword(), true, true, true, true, authorities);
                //daoAuthenticationProvider.getUserCache().putUserInCache(usr);               
                //}
            }
        }
        rs.close();
    } catch (Exception e) {
        log.error("Error connecting to db", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            UserDatabase.recycle(conn);
        }
    }
    return details;
}

From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java

/**
 * Generates a list of projects that the user has access to
 *
 * @param db//from  w  ww  . j a  v  a  2s  .c  o m
 * @param userId
 * @param specificProjectId
 * @param specificCategoryId
 * @return
 * @throws SQLException
 */
public static String generateValidProjects(Connection db, int userId, int specificProjectId,
        int specificCategoryId) throws SQLException {
    if (userId < 1) {
        return "";
    }
    // @todo get ids from user cache
    // @update cache everytime a user is added or removed from a project team
    // get the projects for the user
    // get the project permissions for each project
    // if user has access to the data, then add to query
    StringBuffer projectList = new StringBuffer();
    PreparedStatement pst = db
            .prepareStatement("SELECT project_id " + "FROM project_team " + "WHERE user_id = ? "
                    + "AND status IS NULL " + (specificProjectId > -1 ? "AND project_id = ? " : "")
                    + (specificCategoryId > -1
                            ? "AND project_id IN (SELECT project_id FROM projects WHERE category_id = ?) "
                            : ""));
    int i = 0;
    pst.setInt(++i, userId);
    if (specificProjectId > -1) {
        pst.setInt(++i, specificProjectId);
    }
    if (specificCategoryId > -1) {
        pst.setInt(++i, specificCategoryId);
    }
    ResultSet rs = pst.executeQuery();
    while (rs.next()) {
        int projectId = rs.getInt("project_id");
        // these projects override the lower access projects
        if (projectList.length() > 0) {
            projectList.append(" OR ");
        }
        projectList.append(projectId);
    }
    rs.close();
    pst.close();
    return projectList.toString();
}

From source file:genericepayadmin.AddIpBean.java

public static int getPages(Connection con) throws Exception {
    int totalcount = 0;
    PreparedStatement ps = null;//from   www .j av  a  2  s  .c  om
    ResultSet rs = null;
    try {
        String sql = "select ceil(count(*)/10) as totalpage from webservice_validator";
        ps = con.prepareStatement(sql);
        rs = ps.executeQuery();
        if (rs.next()) {
            totalcount = rs.getInt("totalpage");
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    } finally {
        try {
            if (ps != null)
                ps.close();
            if (rs != null)
                rs.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    return totalcount;
}

From source file:com.sql.EmailOutAttachment.java

/**
 * Gathers a list of attachments for a specific email address.
 * /* w w w  .j av  a 2  s .c om*/
 * @param emailID Integer
 * @return List (EmailOutAttachmentModel) 
 */
public static List<EmailOutAttachmentModel> getAttachmentsByEmail(int emailID) {
    List<EmailOutAttachmentModel> list = new ArrayList();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "SELECT * FROM EmailOutAttachment WHERE emailOutID = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, emailID);
        rs = ps.executeQuery();
        while (rs.next()) {
            EmailOutAttachmentModel item = new EmailOutAttachmentModel();
            item.setId(rs.getInt("id"));
            item.setEmailOutID(rs.getInt("emailOutID"));
            item.setFileName(rs.getString("fileName"));
            list.add(item);
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return list;
}

From source file:dsd.dao.WorstCaseDAO.java

public static ArrayList<WorstPylonCase> GetAllForPeriod(Calendar startDate, Calendar endDate, boolean traffic,
        boolean debris) {
    try {// ww w .  j a  va  2 s  . co m
        Connection con = DAOProvider.getDataSource().getConnection();
        ArrayList<WorstPylonCase> worstCaseDataList = new ArrayList<WorstPylonCase>();
        try {
            String tableName = GetTableNameForDataType(traffic, debris);
            Object[] parameters = new Object[2];
            parameters[0] = new Timestamp(startDate.getTimeInMillis());
            parameters[1] = new Timestamp(endDate.getTimeInMillis());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, "*",
                    " timestamp >= ? and timestamp <= ? ", "", con, parameters);
            while (results.next()) {
                WorstPylonCase dataTuple = new WorstPylonCase(results.getInt(fields[0]));

                Pylon pylon = new Pylon(results.getInt(fields[0]));
                pylon.setN(results.getFloat(fields[1]));
                pylon.setTx(results.getFloat(fields[2]));
                pylon.setTy(results.getFloat(fields[3]));
                pylon.setMx(results.getFloat(fields[4]));
                pylon.setMy(results.getFloat(fields[5]));
                pylon.setM(results.getFloat(fields[6]));

                dataTuple.setPylon(pylon);

                dataTuple.setID(results.getLong("ID"));
                dataTuple.setComboNumber(results.getInt(fields[8]));
                dataTuple.setSafetyFactor(results.getFloat(fields[7]));
                dataTuple.setTimestamp(results.getTimestamp(fields[9]).getTime());

                worstCaseDataList.add(dataTuple);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
        return worstCaseDataList;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return null;

}