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:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getDemocracitJSON(int consultation_id) throws SQLException {
    TreeMap<Integer, String> all = new TreeMap<Integer, String>();
    String selectSQL1 = "SELECT distinct consultation_id FROM enhancedentities;";
    ResultSet rs1 = connection.createStatement().executeQuery(selectSQL1);
    while (rs1.next()) {
        System.out.println(rs1.getString(1));
    }//from  w  w w .  j ava 2 s. c  o  m
    String selectSQL = "SELECT article_id,json_text FROM enhancedentities where consultation_id="
            + consultation_id + ";";
    ResultSet rs = connection.createStatement().executeQuery(selectSQL);
    while (rs.next()) {
        int tid = rs.getInt(1);
        String s = rs.getString(2);
        all.put(tid, s);
    }
    return all;
}

From source file:net.antidot.sql.model.core.SQLConnector.java

/**
 * Get time zone stored in MySQL database. Reference :
 * http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html The result
 * can be NULL if the Timezone can't be determinated.
 * /*from  ww w. j  a  v  a2 s . com*/
 * The appropriated timezone returned follow these priorities : 1) If
 * 
 * @param conn
 * @return
 * @throws SQLException
 */
public static String getTimeZone(Connection conn) throws SQLException {
    if (log.isDebugEnabled())
        log.debug("[SQLConnector:getTimeZone]");
    Statement stmt = conn.createStatement();
    String query = "SELECT @@global.time_zone, @@session.time_zone;";
    ResultSet rs = stmt.executeQuery(query);

    while (rs.next()) {
        // The global time_zone system variable indicates
        // the time zone the server currently is operating in.
        String globalMySQLTimeZone = rs.getString("@@global.time_zone");
        // Initially, the session variable takes its value from the global
        // time_zone variable, but the client can change its own time zone.
        String sessionMySQLTimeZone = rs.getString("@@session.time_zone");
        String mySQLTimeZone = globalMySQLTimeZone;
        if (!globalMySQLTimeZone.equals(sessionMySQLTimeZone)) {
            // Use session time zone in priority
            mySQLTimeZone = sessionMySQLTimeZone;
        }
        if (log.isDebugEnabled())
            log.debug("[SQLConnector:getTimeZone] mySQLTimeZone extracted = " + mySQLTimeZone);
        return getTimeZoneFromMySQLFormat(mySQLTimeZone);
    }
    if (log.isWarnEnabled())
        log.warn(
                "[SQLConnector:getTimeZone] Impossible to read timezone from database. Timezone of current system selected.");
    return timeZoneToStr(TimeZone.getTimeZone("UTC"));
}

From source file:com.act.lcms.db.model.CuratedChemical.java

protected static List<CuratedChemical> fromResultSet(ResultSet resultSet) throws SQLException {
    List<CuratedChemical> results = new ArrayList<>();
    while (resultSet.next()) {
        Integer id = resultSet.getInt(DB_FIELD.ID.getOffset());
        String name = resultSet.getString(DB_FIELD.NAME.getOffset());
        String inchi = resultSet.getString(DB_FIELD.INCHI.getOffset());
        Double mass = resultSet.getDouble(DB_FIELD.MASS.getOffset());
        Integer expectedCollisionVoltage = resultSet.getInt(DB_FIELD.EXPECTED_COLLISION_VOLTAGE.getOffset());
        if (resultSet.wasNull()) {
            expectedCollisionVoltage = null;
        }//from ww w  . j  av a  2 s . co m
        String referenceUrl = resultSet.getString(DB_FIELD.REFERENCE_URL.getOffset());

        results.add(new CuratedChemical(id, name, inchi, mass, expectedCollisionVoltage, referenceUrl));
    }

    return results;
}

From source file:com.cloudera.sqoop.manager.SQLServerManagerExportManualTest.java

public static void checkSQLBinaryTableContent(String[] expected, String tableName, Connection connection) {
    Statement stmt = null;/*from   w  w w  . j  a  v a 2  s.  c  om*/
    ResultSet rs = null;
    try {
        stmt = connection.createStatement();
        rs = stmt.executeQuery("SELECT TOP 1 [b1], [b2] FROM " + tableName);
        rs.next();
        assertEquals(expected[0], rs.getString("b1"));
        assertEquals(expected[1], rs.getString("b2"));
    } catch (SQLException e) {
        LOG.error("Can't verify table content", e);
        fail();
    } finally {
        try {
            connection.commit();

            if (stmt != null) {
                stmt.close();
            }
            if (rs != null) {
                rs.close();
            }
        } catch (SQLException ex) {
            LOG.info("Ignored exception in finally block.");
        }
    }
}

From source file:com.sql.EmailOutRelatedCase.java

public static List<EmailOutRelatedCaseModel> getRelatedCases(EmailOutModel eml) {
    List<EmailOutRelatedCaseModel> list = new ArrayList();
    Connection conn = null;/* w  w w  .  jav a  2 s.c o  m*/
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "SELECT * FROM EmailOutRelatedCase WHERE emailOutId = ? ";

        ps = conn.prepareStatement(sql);
        ps.setInt(1, eml.getId());

        rs = ps.executeQuery();
        while (rs.next()) {
            EmailOutRelatedCaseModel item = new EmailOutRelatedCaseModel();
            item.setId(rs.getInt("id"));
            item.setEmailOutId(rs.getInt("emailOutId"));
            item.setCaseYear(rs.getString("caseYear"));
            item.setCaseType(rs.getString("caseType"));
            item.setCaseMonth(rs.getString("caseMonth"));
            item.setCaseNumber(rs.getString("caseNumber"));
            list.add(item);
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return list;
}

From source file:ca.qc.adinfo.rouge.achievement.db.AchievementDb.java

public static HashMap<String, Achievement> getAchievementList(DBManager dbManager) {

    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    HashMap<String, Achievement> returnValue = new HashMap<String, Achievement>();

    String sql = "SELECT `key`, `name`, `point_value`, `total` FROM rouge_achievements";
    try {/*from  w w w.  j av  a 2 s  . c om*/
        connection = dbManager.getConnection();
        stmt = connection.prepareStatement(sql);

        rs = stmt.executeQuery();

        while (rs.next()) {

            String key = rs.getString("key");

            Achievement achievement = new Achievement(key, rs.getString("name"), rs.getInt("point_value"),
                    rs.getDouble("total"), 0);

            returnValue.put(key, achievement);
        }

        return returnValue;

    } catch (SQLException e) {
        log.error(stmt);
        log.error(e);
        return null;

    } finally {

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

From source file:com.wso2telco.mnc.resolver.mncrange.McnRangeDbUtil.java

public static String getMncBrand(String mcc, String mnc) throws MobileNtException {
    Connection conn = null;/*from   ww w.  j ava 2s  .  c o  m*/
    PreparedStatement ps = null;
    ResultSet rs = null;
    String sql = "SELECT operatorname " + "FROM operators " + "WHERE mcc = ? AND mnc = ?";

    String mncBrand = null;

    try {
        conn = getAxiataDBConnection();
        ps = conn.prepareStatement(sql);
        ps.setString(1, mcc);
        ps.setString(2, mnc);
        rs = ps.executeQuery();
        if (rs.next()) {
            mncBrand = rs.getString("operatorname");
        }
    } catch (SQLException e) {
        handleException("Error occured while getting Brand for for mcc: and mnc: " + mcc + ":" + mnc
                + " from the database", e);
    } finally {
        McnRangeDbUtil.closeAllConnections(ps, conn, rs);
    }
    return mncBrand;
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getDemocracitConsultationBody() throws SQLException {
    TreeMap<Integer, String> cons_body = new TreeMap<>();
    String sql = "SELECT id, short_description, completed_text " + "FROM consultation " + "WHERE id "
    //                + "=3338;";
            + "NOT IN (SELECT consultations_ner.id FROM consultations_ner);";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    while (rs.next()) {
        int consID = rs.getInt("id");
        String cons_desc = rs.getString("short_description");
        //            String cons_compl = rs.getString("completed_text");
        //            if (cons_compl != null) {
        //                String cons_text = cons_compl + "\n" + cons_desc;
        //                cons_body.put(consID, cons_text);
        //            } else {
        cons_body.put(consID, cons_desc);
        //            }
    }//from ww w  .ja v  a2 s  .  c  o  m
    return cons_body;
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getDemocracitCompletedConsultationBody() throws SQLException {
    TreeMap<Integer, String> cons_compl_desc = new TreeMap<>();
    String sql = "SELECT id, completed_text " + "FROM consultation "
            + "WHERE completed = 1 AND id NOT IN (SELECT consultations_ner.id FROM consultations_ner);";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    while (rs.next()) {
        int consID = rs.getInt("id");
        String cons_compl_text = rs.getString("completed_text");
        //            String cons_compl = rs.getString("completed_text");
        //            if (cons_compl != null) {
        //                String cons_text = cons_compl + "\n" + cons_desc;
        //                cons_body.put(consID, cons_text);
        //            } else {
        cons_compl_desc.put(consID, cons_compl_text);
        //            }
    }/* ww w . j a  va  2  s .  c  o  m*/
    return cons_compl_desc;
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getClusterDocuments(int clid) throws SQLException {
    TreeMap<Integer, String> all = new TreeMap<Integer, String>();
    String selectSQL = "SELECT palo_id,raw_text FROM texts_herc where text_id=" + clid + ";";
    ResultSet rs = connection.createStatement().executeQuery(selectSQL);
    while (rs.next()) {
        int tid = rs.getInt(1);
        String s = rs.getString(2);
        all.put(tid, s);//w  ww.  j  a  v a 2  s . c o  m
    }
    return all;
}