Example usage for java.sql ResultSet getString

List of usage examples for java.sql ResultSet getString

Introduction

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

Prototype

String getString(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:com.silverpeas.notation.model.RatingDAO.java

private static RatingRow resultSet2RatingRow(ResultSet rs) throws SQLException {
    return new RatingRow(rs.getInt(COLUMN_ID), rs.getString(COLUMN_INSTANCEID),
            rs.getString(COLUMN_CONTRIBUTION_ID), rs.getString(COLUMN_CONTRIBUTION_TYPE),
            rs.getString(COLUMN_RATER), rs.getInt(COLUMN_RATING));
}

From source file:com.thoughtworks.go.server.datamigration.M001.java

static Migration convertPipelineSelectionsToFilters() {
    return (cxn) -> {
        if (!required(cxn))
            return;

        try (Statement s = cxn.createStatement()) {
            final ResultSet rs = s.executeQuery(
                    "SELECT id, selections, isblacklist FROM pipelineselections WHERE version = 0");
            while (rs.next()) {
                perform(cxn, rs.getLong(ID), rs.getString(SELECTIONS), rs.getBoolean(BLACKLIST));
            }/*from  w  ww.  ja v  a 2  s  .c  o  m*/
        }
    };
}

From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyCustomFunctionsInitializer.java

private static void registerBitwiseFunctions(final Connection con, String schema) throws SQLException {
    DatabaseMetaData dbMeta = con.getMetaData();
    ResultSet rs = dbMeta.getFunctions(null, null, null);
    Set<String> functionNames = new HashSet<String>(Arrays.asList(BITWISE_AND, BITWISE_OR));
    while (rs.next()) {
        String schemaName = rs.getString(2);
        String functionName = rs.getString(3).toUpperCase();
        if (schema.equalsIgnoreCase(schemaName) && functionNames.contains(functionName)) {
            functionNames.remove(functionName);
        }/*  ww w.  j  av  a 2s .  co  m*/
    }

    // at this point, functionNames contains the functions we need to create
    if (functionNames.size() > 0) {
        final String sqlTemplate = "CREATE FUNCTION %s.%s( parm1 INTEGER, param2 INTEGER ) "
                + "RETURNS INTEGER LANGUAGE JAVA DETERMINISTIC PARAMETER STYLE JAVA NO SQL "
                + "EXTERNAL NAME 'net.solarnetwork.node.dao.jdbc.derby.ext.DerbyBitwiseFunctions.%s'";
        if (functionNames.contains(BITWISE_AND)) {
            final String sql = String.format(sqlTemplate, schema, BITWISE_AND, "bitwiseAnd");
            con.createStatement().execute(sql);
        }
        if (functionNames.contains(BITWISE_OR)) {
            final String sql = String.format(sqlTemplate, schema, BITWISE_OR, "bitwiseOr");
            con.createStatement().execute(sql);
        }
    }
}

From source file:com.ineunet.knife.security.SysParams.java

public static String getValue(String key) {
    Asserts.notBlank(key);/*from  www . j  a v  a2 s . c o m*/
    SysParam param = cache.get(key);
    if (param != null)
        return param.getValue();
    else {
        List<SysParam> params = PersistUtils.getJdbcTemplate()
                .query("select id,value from knife_sys_param where id=?", new RowMapper<SysParam>() {
                    @Override
                    public SysParam mapRow(ResultSet rs, int rowNum) throws SQLException {
                        SysParam sp = new SysParam();
                        sp.setId(rs.getString("id"));
                        sp.setValue(rs.getString("value"));
                        return sp;
                    }
                }, key);
        if (params.isEmpty())
            return null;
        param = params.get(0);
        cache.put(key, param);
        return param.getValue();
    }
}

From source file:com.bluepandora.therap.donatelife.jsonbuilder.DistrictJson.java

public static JSONObject getDistrictJson(ResultSet result) throws JSONException {
    JSONObject jsonObject;//from w  ww. j av  a 2 s  . c o  m
    JSONArray jsonArray = new JSONArray();
    try {

        while (result.next()) {
            jsonObject = new JSONObject();
            jsonObject.put(DIST_ID, result.getString("dist_id"));
            jsonObject.put(DIST_NAME, result.getString("dist_name"));
            jsonObject.put(DIST_BNAME, result.getString("dist_bname"));
            jsonArray.put(jsonObject);
        }
        jsonObject = new JSONObject();
        jsonObject.put(DISTRICT, jsonArray);
        jsonObject.put(DONE, 1);

    } catch (SQLException error) {

        Debug.debugLog("DISTRICT JSON ERROR: ", error);
        jsonObject = new JSONObject();
        jsonObject.put(DONE, 0);
    }
    return jsonObject;

}

From source file:com.bluepandora.therap.donatelife.jsonbuilder.HospitalJson.java

public static JSONObject getHospitalJson(ResultSet result) throws JSONException {
    JSONObject jsonObject;/*from  www . ja va 2 s. co m*/
    JSONArray jsonArray = new JSONArray();
    try {

        while (result.next()) {
            jsonObject = new JSONObject();
            jsonObject.put(DIST_ID, result.getString("dist_id"));
            jsonObject.put(HOSP_ID, result.getString("hospital_id"));
            jsonObject.put(HOSP_NAME, result.getString("hospital_name"));
            jsonObject.put(HOSP_BNAME, result.getString("hospital_bname"));
            jsonArray.put(jsonObject);
        }
        jsonObject = new JSONObject();
        jsonObject.put(HOSPITAL, jsonArray);
        jsonObject.put(DONE, 1);

    } catch (SQLException error) {

        Debug.debugLog("HOSPITAL JSON ERROR: ", error);
        jsonObject = new JSONObject();
        jsonObject.put(DONE, 0);
    }
    return jsonObject;
}

From source file:com.silverpeas.gallery.dao.OrderDAO.java

/**
 * Finds orders from the specified criteria.
 * @param con/* w ww .  j  a  v a 2 s.  com*/
 * @param criteria
 * @return a list of orders, empty if no order found.
 */
public static List<Order> findByCriteria(final Connection con, MediaOrderCriteria criteria)
        throws SQLException {

    MediaOrderSQLQueryBuilder queryBuilder = new MediaOrderSQLQueryBuilder();
    criteria.processWith(queryBuilder);

    Pair<String, List<Object>> queryBuild = queryBuilder.result();

    return queryBuilder.orderingResult(
            select(con, queryBuild.getLeft(), queryBuild.getRight(), new SelectResultRowProcessor<Order>() {

                @Override
                protected Order currentRow(final int rowIndex, final ResultSet rs) throws SQLException {
                    Order order = new Order(rs.getString(1));
                    order.setUserId(rs.getString(2));
                    order.setInstanceId(rs.getString(3));
                    order.setCreationDate(rs.getTimestamp(4));
                    order.setProcessDate(rs.getTimestamp(5));
                    order.setProcessUserId(rs.getString(6));
                    order.setRows(getAllOrderDetails(con, order.getOrderId()));
                    return order;
                }
            }));
}

From source file:net.sf.sprockets.sql.Statements.java

/**
 * Execute the query, get the String values in the first column of the result set, and close the
 * statement./*  w w w. j av a 2 s . c  o  m*/
 * 
 * @param stmt
 *            must already have parameters set
 * @return null if the result set is empty
 * @since 1.5.0
 */
public static List<String> allStrings(PreparedStatement stmt) throws SQLException {
    List<String> s = null;
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) {
        s = new ArrayList<String>();
        do {
            s.add(rs.getString(1));
        } while (rs.next());
    }
    stmt.close();
    return s;
}

From source file:com.handany.base.generator.Generator.java

public static List<TableBean> getTables() {
    Properties p = new Properties();
    try {//from   w  ww. j a va 2  s  .  c om
        p.load(new FileInputStream(new File("src/main/java/com/handany/base/generator/generator.properties")));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<TableBean> tableBeanList = jdbcTemplate.query("select * from TABLES where table_schema = ?",
            new Object[] { SCHEMA_NAME }, new RowMapper<TableBean>() {
                @Override
                public TableBean mapRow(ResultSet rs, int i) throws SQLException {
                    TableBean bean = new TableBean();
                    String tableName = rs.getString("table_name");
                    bean.setTableName(tableName);
                    bean.setTableNameNoDash(delDash(tableName));
                    bean.setTableNameCapitalized(StringUtils.capitalize(bean.getTableNameNoDash()));
                    bean.setTableComment(rs.getString("table_comment"));
                    return bean;
                }
            });

    for (TableBean tableBean : tableBeanList) {
        tableBean.setColumnBeanList(getColumns(tableBean));
    }

    return tableBeanList;
}

From source file:com.oracle.tutorial.jdbc.SuppliersTable.java

public static void viewTable(Connection con) throws SQLException {
    Statement stmt = null;/*from ww w .  j  av  a 2  s.c o  m*/
    String query = "select SUP_ID, SUP_NAME, STREET, CITY, STATE, ZIP from SUPPLIERS";
    try {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            int supplierID = rs.getInt("SUP_ID");
            String supplierName = rs.getString("SUP_NAME");
            String street = rs.getString("STREET");
            String city = rs.getString("CITY");
            String state = rs.getString("STATE");
            String zip = rs.getString("ZIP");
            System.out.println(
                    supplierName + "(" + supplierID + "): " + street + ", " + city + ", " + state + ", " + zip);
        }
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}