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.keybox.manage.db.PublicKeyDB.java

public static List<String> getPublicKeysForSystem(Connection con, Long systemId) {
    List<String> publicKeyList = new ArrayList<>();

    if (systemId == null) {
        systemId = -99L;/*w w w  . j  a v a  2  s  . com*/
    }
    try {
        PreparedStatement stmt = con.prepareStatement(
                "select * from public_keys where (profile_id is null or profile_id in (select profile_id from system_map where system_id=?)) and enabled=true");
        stmt.setLong(1, systemId);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            publicKeyList.add(rs.getString(PUBLIC_KEY));
        }
        DBUtils.closeStmt(stmt);

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

    return publicKeyList;

}

From source file:com.tethrnet.manage.db.SystemDB.java

/**
 * returns system by id//from   ww  w .  j av  a 2s .  com
 *
 * @param con DB connection
 * @param id  system id
 * @return system
 */
public static HostSystem getSystem(Connection con, Long id) {

    HostSystem hostSystem = null;

    try {

        PreparedStatement stmt = con.prepareStatement("select * from  system where id=?");
        stmt.setLong(1, id);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            hostSystem = new HostSystem();
            hostSystem.setId(rs.getLong("id"));
            hostSystem.setDisplayNm(rs.getString("display_nm"));
            hostSystem.setUser(rs.getString("user"));
            hostSystem.setHost(rs.getString("host"));
            hostSystem.setPort(rs.getInt("port"));
            hostSystem.setAuthorizedKeys(rs.getString("authorized_keys"));
            hostSystem.setStatusCd(rs.getString("status_cd"));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

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

    return hostSystem;
}

From source file:com.datatorrent.contrib.hive.HiveMockTest.java

public static void hiveInitializePOJODatabase(HiveStore hiveStore) throws SQLException {
    hiveStore.connect();/*from   ww  w .  j av  a2 s .c  om*/
    Statement stmt = hiveStore.getConnection().createStatement();
    // show tables
    String sql = "show tables";

    LOG.debug(sql);
    ResultSet res = stmt.executeQuery(sql);
    if (res.next()) {
        LOG.debug("tables are {}", res.getString(1));
    }
    stmt.execute("DROP TABLE " + tablepojo);

    stmt.execute("CREATE TABLE " + tablepojo + " (col1 int) PARTITIONED BY(dt STRING) ROW FORMAT DELIMITED "
            + "FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' \n" + "STORED AS TEXTFILE ");
    hiveStore.disconnect();
}

From source file:com.wso2telco.dep.reportingservice.dao.ApiManagerDAO.java

/**
 * Gets the consumer key by application.
 *
 * @param applicationId the application id
 * @return the consumer key by application
 * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception
 * @throws SQLException the SQL exception
 *//* www  .j  a v  a2  s .c om*/
public static String getConsumerKeyByApplication(int applicationId)
        throws APIMgtUsageQueryServiceClientException, SQLException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet results = null;
    String sql = "SELECT CONSUMER_KEY FROM " + ReportingTable.AM_APPLICATION_KEY_MAPPING
            + " WHERE KEY_TYPE = 'PRODUCTION' AND APPLICATION_ID=?";
    String consumerKey = null;

    try {
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_DB);
        ps = conn.prepareStatement(sql);
        ps.setInt(1, applicationId);
        log.debug("getConsumerKeyByApplication");
        results = ps.executeQuery();
        while (results.next()) {
            consumerKey = results.getString("CONSUMER_KEY");
        }
    } catch (Exception e) {
        log.error("Error occured while getting consumer key from the database" + e);
    } finally {
        DbUtils.closeAllConnections(ps, conn, results);
    }

    return consumerKey;
}

From source file:com.fpuna.preproceso.PreprocesoTS.java

public static HashMap<String, SessionTS> leerBDtrainingSet(String BD, String sensor) {
    HashMap<String, SessionTS> SessionsTotal = new HashMap<String, SessionTS>();
    String Consulta;/* w w  w .  jav a 2 s. c om*/
    Connection c = null;
    Statement stmt = null;
    Registro reg = new Registro();

    Consulta = "SELECT dat.statusId, dat.sensorName, dat.\"value\", dat.\"timestamp\", lb.\"name\"\n"
            + "FROM sensor_data AS dat, status AS st, label AS lb\n"
            + "WHERE dat.statusId = st.\"_id\" AND st.labelId = lb.\"_id\" ORDER BY dat.\"timestamp\"";
    try {
        Class.forName("org.sqlite.JDBC");
        c = DriverManager.getConnection("jdbc:sqlite:" + path + "sensor.db");
        c.setAutoCommit(false);
        System.out.println("Opened database successfully");
        stmt = c.createStatement();
        ResultSet rs = stmt.executeQuery(Consulta);

        while (rs.next()) {
            reg = new Registro();
            reg.setSensor(rs.getString("sensorName"));
            reg.setTiempo(rs.getTimestamp("timestamp"));

            String[] values = (rs.getString("value")).split("\\,");

            if (values.length == 3) {
                reg.setValor_x(Double.parseDouble(values[0].substring(1)));
                reg.setValor_y(Double.parseDouble(values[1]));
                reg.setValor_z(Double.parseDouble(values[2].substring(0, values[2].length() - 1)));
            } else if (values.length == 5) {
                reg.setValor_x(Double.parseDouble(values[0].substring(1)));
                reg.setValor_y(Double.parseDouble(values[1]));
                reg.setValor_z(Double.parseDouble(values[2]));
                reg.setM_1(Double.parseDouble(values[3]));
                reg.setM_2(Double.parseDouble(values[4].substring(0, values[4].length() - 1)));
            }

            if (SessionsTotal.containsKey(rs.getString("statusId"))) {
                SessionTS s = SessionsTotal.get(rs.getString("statusId"));
                s.addRegistro(reg);
                SessionsTotal.replace(rs.getString("statusId"), s);
            } else {
                SessionTS s = new SessionTS();
                s.setActividad(rs.getString("name"));
                s.addRegistro(reg);
                SessionsTotal.put(rs.getString("statusId"), s);
            }
        }
        rs.close();
        stmt.close();
        c.close();

    } catch (ClassNotFoundException | SQLException | NumberFormatException e) {
        System.err.println("Okapu:" + e.getClass().getName() + ": " + e.getMessage());
        System.exit(0);
    }
    System.out.println("Operation done successfully");
    return SessionsTotal;
}

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

/**
 * returns system by id//from w ww .j a  v  a 2  s .  c o m
 *
 * @param con DB connection
 * @param id  system id
 * @return system
 */
public static HostSystem getSystem(Connection con, Long id) {

    HostSystem hostSystem = null;

    try {

        PreparedStatement stmt = con.prepareStatement("select * from  system where id=?");
        stmt.setLong(1, id);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            hostSystem = new HostSystem();
            hostSystem.setId(rs.getLong("id"));
            hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
            hostSystem.setUser(rs.getString("user"));
            hostSystem.setHost(rs.getString("host"));
            hostSystem.setPort(rs.getInt("port"));
            hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
            hostSystem.setStatusCd(rs.getString(STATUS_CD));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

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

    return hostSystem;
}

From source file:com.wso2telco.dep.reportingservice.dao.OperatorDAO.java

/**
 * Gets the all operators./*from   w w w.  j a v a2s  .  c  o m*/
 *
 * @return the all operators
 * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception
 * @throws SQLException the SQL exception
 */
public static List<String> getAllOperators() throws APIMgtUsageQueryServiceClientException, SQLException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet results = null;
    String sql = "SELECT operatorname FROM " + ReportingTable.OPERATORS + "";
    List<String> op = new ArrayList<String>();
    try {
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB);
        ps = conn.prepareStatement(sql);
        log.debug("getAllOperators for ID");
        results = ps.executeQuery();
        while (results.next()) {
            String temp = results.getString("operatorname");
            op.add(temp);
        }
    } catch (Exception e) {
        log.error("Error occured while getting All Operators from the database" + e);
    } finally {
        DbUtils.closeAllConnections(ps, conn, results);
    }
    return op;
}

From source file:genericepayadmin.AddIpBean.java

public static ArrayList getTreasury(Connection con) throws Exception {
    PreparedStatement ps = null;/*  ww w. jav a  2s .com*/
    ResultSet rs = null;
    ArrayList al = new ArrayList();

    try {
        String sql = "select wbser.active, wbser.id, gdep.dept_name, wbser.ipaddress,wbser.checksum from webservice_validator wbser,generic_dept gdep "
                + " where gdep.DEPT_ID=wbser.deptid ";
        ps = con.prepareStatement(sql);

        rs = ps.executeQuery();
        while (rs.next()) {
            AddIpBean tbean = new AddIpBean();
            tbean.setId(rs.getString("id"));
            tbean.setDept_name(rs.getString("dept_name"));
            tbean.setIpaddress(rs.getString("ipaddress"));
            tbean.setChecksum(rs.getString("checksum"));
            tbean.setStatus(rs.getString("active"));
            al.add(tbean);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    } finally {
        if (ps != null)
            ps.close();
        if (rs != null)
            rs.close();
    }
    return al;
}

From source file:com.datatorrent.contrib.hive.HiveMockTest.java

public static void hiveInitializeDatabase(HiveStore hiveStore) throws SQLException {
    hiveStore.connect();/* w  ww . j a v a2s .  c o m*/
    Statement stmt = hiveStore.getConnection().createStatement();
    // show tables
    String sql = "show tables";

    LOG.debug(sql);
    ResultSet res = stmt.executeQuery(sql);
    if (res.next()) {
        LOG.debug("tables are {}", res.getString(1));
    }

    stmt.execute("DROP TABLE " + tablename);

    stmt.execute("CREATE TABLE IF NOT EXISTS " + tablename + " (col1 String) PARTITIONED BY(dt STRING) "
            + "ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'  \n"
            + "STORED AS TEXTFILE ");
    /*ResultSet res = stmt.execute("CREATE TABLE IF NOT EXISTS temp4 (col1 map<string,int>,col2 map<string,int>,col3  map<string,int>,col4 map<String,timestamp>, col5 map<string,double>,col6 map<string,double>,col7 map<string,int>,col8 map<string,int>) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','  \n"
     + "COLLECTION ITEMS TERMINATED BY '\n'  \n"
     + "MAP KEYS TERMINATED BY ':'  \n"
     + "LINES TERMINATED BY '\n' "
     + "STORED AS TEXTFILE");*/

    hiveStore.disconnect();
}