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:massbank.svn.SVNUtils.java

/**
 *
 *///from  w ww .  j a  v  a 2s.c om
public static boolean checkDBExists(String dbName) {
    if (dbName.equals("")) {
        return false;
    }
    Connection con = connectDB(dbName);
    if (con == null) {
        return false;
    }
    try {
        Statement stmt = con.createStatement();
        String sql = "SHOW TABLES LIKE 'SPECTRUM'";
        ResultSet rs = stmt.executeQuery(sql);
        String val = "";
        if (rs.first()) {
            val = rs.getString(1);
        }
        con.close();
        if (!val.equals("")) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

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

public static void getCoffeesBoughtBySupplier(String supplierName, Connection con) throws SQLException {
    Statement stmt = null;/*  w w  w  . j  av a  2 s .  c  o m*/
    String query = "SELECT COFFEES.COF_NAME " + "FROM COFFEES, SUPPLIERS " + "WHERE SUPPLIERS.SUP_NAME LIKE '"
            + supplierName + "' " + "and SUPPLIERS.SUP_ID = COFFEES.SUP_ID";

    try {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        System.out.println("Coffees bought from " + supplierName + ": ");
        while (rs.next()) {
            String coffeeName = rs.getString(1);
            System.out.println("     " + coffeeName);
        }
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

From source file:com.ineunet.knife.persist.PersistUtils.java

public static boolean existsTable(final String tableName, JdbcTemplate jdbcTemplate) {
    return jdbcTemplate.query("show tables", new ResultSetExtractor<Boolean>() {
        @Override//from   w w  w. j av a  2 s  .  co  m
        public Boolean extractData(ResultSet rs) throws SQLException, DataAccessException {
            while (rs.next()) {
                String tableNameOther = rs.getString(1);
                if (tableName.equalsIgnoreCase(tableNameOther))
                    return true;
            }
            return false;
        }
    });
}

From source file:com.ec2box.manage.db.UserThemeDB.java

/**
 * get user theme/*from  w ww . j  av  a2s. c om*/
 *
 * @param userId object
 * @return user theme object
 */
public static UserSettings getTheme(Long userId) {

    UserSettings theme = null;
    Connection con = null;
    try {
        con = DBUtils.getConn();

        PreparedStatement stmt = con.prepareStatement("select * from user_theme where user_id=?");
        stmt.setLong(1, userId);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            theme = new UserSettings();
            theme.setBg(rs.getString("bg"));
            theme.setFg(rs.getString("fg"));
            if (StringUtils.isNotEmpty(rs.getString("d1"))) {
                String[] colors = new String[16];
                colors[0] = rs.getString("d1");
                colors[1] = rs.getString("d2");
                colors[2] = rs.getString("d3");
                colors[3] = rs.getString("d4");
                colors[4] = rs.getString("d5");
                colors[5] = rs.getString("d6");
                colors[6] = rs.getString("d7");
                colors[7] = rs.getString("d8");
                colors[8] = rs.getString("b1");
                colors[9] = rs.getString("b2");
                colors[10] = rs.getString("b3");
                colors[11] = rs.getString("b4");
                colors[12] = rs.getString("b5");
                colors[13] = rs.getString("b6");
                colors[14] = rs.getString("b7");
                colors[15] = rs.getString("b8");
                theme.setColors(colors);
            }
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DBUtils.closeConn(con);
    }

    return theme;

}

From source file:com.senior.g40.service.UserService.java

private static void setUser(ResultSet rs, User usr) throws SQLException {
    usr.setUserId(rs.getLong(""));
    usr.setUsername(rs.getString(""));
    usr.setPassword(rs.getString(""));
    usr.setUserType(rs.getString("").charAt(0));
}

From source file:com.keybox.manage.db.UserThemeDB.java

/**
 * get user theme/*from   w  w  w.j a  va 2s  .c o m*/
 *
 * @param userId object
 * @return user theme object
 */
public static UserSettings getTheme(Long userId) {

    UserSettings theme = null;
    Connection con = null;
    try {
        con = DBUtils.getConn();

        PreparedStatement stmt = con.prepareStatement("select * from user_theme where user_id=?");
        stmt.setLong(1, userId);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            theme = new UserSettings();
            theme.setBg(rs.getString("bg"));
            theme.setFg(rs.getString("fg"));
            if (StringUtils.isNotEmpty(rs.getString("d1"))) {
                String[] colors = new String[16];
                colors[0] = rs.getString("d1");
                colors[1] = rs.getString("d2");
                colors[2] = rs.getString("d3");
                colors[3] = rs.getString("d4");
                colors[4] = rs.getString("d5");
                colors[5] = rs.getString("d6");
                colors[6] = rs.getString("d7");
                colors[7] = rs.getString("d8");
                colors[8] = rs.getString("b1");
                colors[9] = rs.getString("b2");
                colors[10] = rs.getString("b3");
                colors[11] = rs.getString("b4");
                colors[12] = rs.getString("b5");
                colors[13] = rs.getString("b6");
                colors[14] = rs.getString("b7");
                colors[15] = rs.getString("b8");
                theme.setColors(colors);
            }
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);

    return theme;

}

From source file:at.alladin.rmbt.db.dao.TestStatDao.java

/**
 * //from  www  .j a va 2  s . c  om
 * @param rs
 * @return
 * @throws SQLException
 * @throws JSONException
 */
private static TestStat instantiateItem(ResultSet rs) throws SQLException, JSONException {
    TestStat result = new TestStat();
    result.setTestUid(rs.getLong("test_uid"));
    result.setCpuUsage(new JSONObject(rs.getString("cpu_usage")));
    result.setMemUsage(new JSONObject(rs.getString("mem_usage")));
    return result;
}

From source file:Student.java

public static void checkData() throws Exception {
        Class.forName("org.hsqldb.jdbcDriver");
        Connection conn = DriverManager.getConnection("jdbc:hsqldb:data/tutorial", "sa", "");
        Statement st = conn.createStatement();

        ResultSet mrs = conn.getMetaData().getTables(null, null, null, new String[] { "TABLE" });
        while (mrs.next()) {
            String tableName = mrs.getString(3);
            System.out.println("\n\n\n\nTable Name: " + tableName);

            ResultSet rs = st.executeQuery("select * from " + tableName);
            ResultSetMetaData metadata = rs.getMetaData();
            while (rs.next()) {
                System.out.println(" Row:");
                for (int i = 0; i < metadata.getColumnCount(); i++) {
                    System.out.println("    Column Name: " + metadata.getColumnLabel(i + 1) + ",  ");
                    System.out.println("    Column Type: " + metadata.getColumnTypeName(i + 1) + ":  ");
                    Object value = rs.getObject(i + 1);
                    System.out.println("    Column Value: " + value + "\n");
                }//from   w  w w .j a v a 2 s  .  co m
            }
        }
    }

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

/**
 * Gets all medias of an order./*from  ww w. j  av  a2 s .  c  om*/
 * @param con
 * @param orderId
 * @return
 * @throws SQLException
 */
public static List<OrderRow> getAllOrderDetails(Connection con, final String orderId) throws SQLException {
    return select(con,
            "select mediaId, instanceId, downloadDate, downloadDecision  from SC_Gallery_OrderDetail "
                    + "where orderId = ?",
            orderId, new SelectResultRowProcessor<OrderRow>() {

                @Override
                protected OrderRow currentRow(final int rowIndex, final ResultSet rs) throws SQLException {
                    String mediaId = rs.getString(1);
                    String instanceId = rs.getString(2);
                    OrderRow orderRow = new OrderRow(orderId, mediaId, instanceId);
                    orderRow.setDownloadDate(rs.getTimestamp(3));
                    orderRow.setDownloadDecision(rs.getString(4));
                    return orderRow;
                }
            });
}

From source file:com.senior.g40.service.UserService.java

private static void setProfile(ResultSet rs, Profile pf) throws SQLException {
    pf.setUserId(rs.getLong("userId"));
    pf.setFirstName(rs.getString("firstName"));
    pf.setLastName(rs.getString("lastName"));
    pf.setPersonalId(rs.getLong("personalId"));
    pf.setPhoneNumber(rs.getString("phone"));
    pf.setAddress1(rs.getString("address1"));
    pf.setAddress2(rs.getString("address2"));
    pf.setAge(rs.getInt("age"));
    pf.setGender(rs.getString("gender").charAt(0));
}