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:net.big_oh.common.jdbc.JdbcProxyExerciser.java

private static void exercisePreparedSelect(Connection con) throws SQLException {
    logger.info(StringUtils.center("exercise prepared select", 100, "-"));

    PreparedStatement preparedStmnt = null;
    ResultSet rs = null;
    try {//from w  w  w.ja  va  2  s  .c  o m
        preparedStmnt = con.prepareStatement("SELECT * FROM TEST_TABLE WHERE TEST_COLUMN = ?");
        preparedStmnt.setString(1, "value1");
        rs = preparedStmnt.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString("TEST_COLUMN"));
        }
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(preparedStmnt);
    }
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

private static void updateArea(String fid) {

    try {//  ww  w .jav  a2 s  . c om
        Connection conn = getConnection();
        String sql = "SELECT pid from objects where area_km is null and st_geometrytype(the_geom) <> 'Point'";
        if (fid != null) {
            sql = sql + " and fid = '" + fid + "'";
        }

        sql = sql + " limit 200000;";

        System.out.println("loading area_km ...");
        Statement s1 = conn.createStatement();
        ResultSet rs1 = s1.executeQuery(sql);

        LinkedBlockingQueue<String> data = new LinkedBlockingQueue<String>();
        while (rs1.next()) {
            data.put(rs1.getString("pid"));
        }

        CountDownLatch cdl = new CountDownLatch(data.size());

        AreaThread[] threads = new AreaThread[CONCURRENT_THREADS];
        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j] = new AreaThread(data, cdl, getConnection().createStatement());
            threads[j].start();
        }

        cdl.await();

        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j].s.close();
            threads[j].interrupt();
        }
        rs1.close();
        s1.close();
        conn.close();
        return;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return;
}

From source file:net.ontopia.topicmaps.cmdlineutils.rdbms.RDBMSIndexTool.java

protected static Map getIndexes(String table_name, DatabaseMetaData dbm) throws SQLException {
    // returns { table_name(colname,...) : index_name }
    Map result = new HashMap(5);
    ResultSet rs = dbm.getIndexInfo(null, null, table_name, false, false);
    String prev_index_name = null;
    String columns = null;/*  w ww  . j a  v a  2  s  .com*/

    while (rs.next()) {
        String index_name = rs.getString(6);

        if (prev_index_name != null && !prev_index_name.equals(index_name)) {
            result.put(table_name + '(' + columns + ')', prev_index_name);
            columns = null;
        }
        // column_name might be quoted, so unquote it before proceeding
        String column_name = unquote(rs.getString(9), dbm.getIdentifierQuoteString());

        if (columns == null)
            columns = column_name;
        else
            columns = columns + "," + column_name;

        prev_index_name = index_name;
    }
    rs.close();

    if (prev_index_name != null)
        result.put(table_name + '(' + columns + ')', prev_index_name);

    return result;
}

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

public static Tags tags(File f, String catalog, Tags t) {
    try {//from   w w  w .jav a2s. c  o  m
        if (t == null) {
            ResultSet rs = connection.createStatement().executeQuery("SELECT TAGS FROM TAGS WHERE PATH = \""
                    + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\"");
            if (!rs.next())
                return new Tags();

            return new Tags(rs.getString(1).split(", "));
        } else {
            if (t.getTags().length == 0)
                connection.createStatement().executeUpdate("DELETE FROM TAGS WHERE PATH = \""
                        + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\"");
            else
                connection.createStatement()
                        .executeUpdate("INSERT OR REPLACE INTO TAGS VALUES(\"" + f.getPath().replace("\\", "/")
                                + "\", \"" + catalog + "\", \"" + t.serialize() + "\")");
        }
    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    return null;
}

From source file:fll.JudgeInformation.java

/**
 * Get all judges stored for this tournament.
 * /*from  w  w  w .j a v  a2s.c o  m*/
 * @param connection the database
 * @param tournament tournament ID
 * @return the judges
 * @throws SQLException
 */
public static Collection<JudgeInformation> getJudges(final Connection connection, final int tournament)
        throws SQLException {
    Collection<JudgeInformation> judges = new LinkedList<JudgeInformation>();

    ResultSet rs = null;
    PreparedStatement stmt = null;
    try {
        stmt = connection.prepareStatement("SELECT id, category, station FROM Judges WHERE Tournament = ?");
        stmt.setInt(1, tournament);
        rs = stmt.executeQuery();
        while (rs.next()) {
            final String id = rs.getString(1);
            final String category = rs.getString(2);
            final String station = rs.getString(3);
            final JudgeInformation judge = new JudgeInformation(id, category, station);
            judges.add(judge);
        }
    } finally {
        SQLFunctions.close(rs);
        SQLFunctions.close(stmt);
    }

    return judges;
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

private static void updateBbox() {

    try {/*  w  w  w .jav a 2  s  .  c o m*/
        Connection conn = getConnection();
        String sql = "SELECT pid from objects where bbox is null limit 200000;";
        logger.info("loading bbox ...");
        Statement s1 = conn.createStatement();
        ResultSet rs1 = s1.executeQuery(sql);

        LinkedBlockingQueue<String[]> data = new LinkedBlockingQueue<String[]>();
        while (rs1.next()) {
            data.put(new String[] { rs1.getString("pid") });
        }

        CountDownLatch cdl = new CountDownLatch(data.size());

        BboxThread[] threads = new BboxThread[CONCURRENT_THREADS];
        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j] = new BboxThread(data, cdl, getConnection().createStatement());
            threads[j].start();
        }

        cdl.await();

        for (int j = 0; j < CONCURRENT_THREADS; j++) {
            threads[j].s.close();
            threads[j].interrupt();
        }
        return;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return;
}

From source file:com.example.querybuilder.server.Jdbc.java

public static String getString(ResultSet resultSet, int columnNumber) {
    try {/*www .  j a va 2 s  .co  m*/
        return resultSet.getString(columnNumber);
    } catch (SQLException e) {
        throw new SqlRuntimeException(e);
    }
}

From source file:Main.java

private static void outputResultSet(ResultSet rs) throws Exception {
    ResultSetMetaData rsMetaData = rs.getMetaData();
    int numberOfColumns = rsMetaData.getColumnCount();
    for (int i = 1; i < numberOfColumns + 1; i++) {
        String columnName = rsMetaData.getColumnName(i);
        System.out.print(columnName + "   ");

    }/*  w ww  .  ja  v a 2  s  . c  o m*/
    while (rs.next()) {
        for (int i = 1; i < numberOfColumns + 1; i++) {
            System.out.print(rs.getString(i) + "   ");
        }
        System.out.println();
    }

}

From source file:edu.jhu.pha.vospace.oauth.MySQLOAuthProvider2.java

/**
 * Returns the user the share is made for
 * @param shareId/*from   w ww  .ja va  2 s  .c  o  m*/
 * @return
 */
public static synchronized List<String> getShareUsers(final String shareId) {
    return DbPoolServlet.goSql("Get share user logins",
            "select identity from user_identities JOIN user_groups ON user_groups.user_id = user_identities.user_id JOIN container_shares ON user_groups.group_id = container_shares.group_id AND container_shares.share_id = ?",
            new SqlWorker<List<String>>() {
                @Override
                public List<String> go(Connection conn, PreparedStatement stmt) throws SQLException {
                    stmt.setString(1, shareId);
                    List<String> returnVect = new Vector<String>();
                    ResultSet rs = stmt.executeQuery();
                    while (rs.next()) {
                        returnVect.add(rs.getString(1));
                    }
                    return returnVect;
                }
            });
}

From source file:com.autentia.tnt.version.Version.java

public static Version getDatabaseVersion(Connection con) throws SQLException {
    Statement stmt = null;//from w ww . java2  s .c om
    ResultSet rs = null;
    String ret = null;

    try {
        stmt = con.createStatement();
        rs = stmt.executeQuery("select version from Version");

        if (rs.next()) {
            ret = rs.getString("version");
        }
    } catch (SQLException e) {
        throw e;
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                log.error("Error al liberar el resultset", e);
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                log.error("Error al liberar el statement", e);
            }
        }
    }

    return new Version(ret == null ? "0" : ret);
}