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.enonic.cms.upgrade.task.UpgradeModel0204.java

private static VirtualFileItem createVirtualFileItem(final ResultSet rs) throws SQLException {
    VirtualFileItem item = new VirtualFileItem();

    final String vf_skey = rs.getString("vf_skey");
    item.key = vf_skey;/*from  w w  w. j  a  va  2 s. c om*/
    item.name = rs.getString("vf_sname");
    item.parentKey = rs.getString("vf_sparentkey");
    item.length = rs.getLong("vf_llength");
    item.blobkey = rs.getString("vf_sblobkey");
    return item;
}

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

public static JSONObject getDonationRecordJson(ResultSet result) throws JSONException {
    JSONArray jsonArray = new JSONArray();
    JSONObject jsonObject;/* w w w .jav  a  2 s.  c o  m*/

    try {

        while (result.next()) {
            jsonObject = new JSONObject();
            jsonObject.put(DONATION_DATE, result.getString("donation_date"));
            jsonObject.put(DONATION_RECORD, result.getString("donation_detail"));
            jsonArray.put(jsonObject);
        }

        if (jsonArray.length() != 0) {
            jsonObject = new JSONObject();
            jsonObject.put(DONATION_RECORD, jsonArray);
            jsonObject.put(DONE, 1);
        } else {
            jsonObject = new JSONObject();
            jsonObject.put("message", Enum.MESSAGE_DONATION_NOT_FOUND);
            jsonObject.put(DONE, 0);
        }

    } catch (SQLException error) {
        Debug.debugLog("BLOOD_GROUP RESULT SET: ", error);
        jsonObject = new JSONObject();
        jsonObject.put(DONE, 0);

    }
    return jsonObject;

}

From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java

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

    Statement stmt = null;/*from   w w w.  j  av a  2 s  .c  o m*/
    ResultSet rs = null;
    try {
        stmt = con.createStatement();
        rs = stmt.executeQuery("SELECT * FROM TEST_TABLE");
        while (rs.next()) {
            System.out.println(rs.getString("TEST_COLUMN"));
        }
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
    }

}

From source file:org.ulyssis.ipp.snapshot.Event.java

public static List<Event> loadFrom(Connection connection, Instant time) throws SQLException, IOException {
    String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" "
            + "WHERE \"time\" >= ? ORDER BY \"time\" ASC, \"id\" ASC";
    List<Event> events = new ArrayList<>();
    try (PreparedStatement stmt = connection.prepareStatement(statement)) {
        stmt.setTimestamp(1, Timestamp.from(time));
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            String evString = rs.getString("data");
            Event event = Serialization.getJsonMapper().readValue(evString, Event.class);
            event.id = rs.getLong("id");
            event.removed = rs.getBoolean("removed");
            events.add(event);//from  w ww.j  ava2 s.c o m
        }
    }
    return events;
}

From source file:eu.earthobservatory.testsuite.utils.Utils.java

public static void createdb() throws Exception {
    String url = "";
    ArrayList<String> databases = new ArrayList<String>();
    PreparedStatement pst = null;

    //Read properties
    Properties properties = new Properties();
    InputStream propertiesStream = Utils.class.getResourceAsStream(dbPropertiesFile);
    properties.load(propertiesStream);/*from w  w  w.  j  a va  2s  .c  om*/

    if ((databaseTemplateName = System.getProperty("postgis.databaseTemplateName")) == null) {
        databaseTemplateName = properties.getProperty("postgis.databaseTemplateName");
    }

    if ((serverName = System.getProperty("postgis.serverName")) == null) {
        serverName = properties.getProperty("postgis.serverName");
    }

    if ((username = System.getProperty("postgis.username")) == null) {
        username = properties.getProperty("postgis.username");
    }

    if ((password = System.getProperty("postgis.password")) == null) {
        password = properties.getProperty("postgis.password");
    }

    if ((port = System.getProperty("postgis.port")) == null) {
        port = properties.getProperty("postgis.port");
    }

    //Connect to server and create the temp database
    url = "jdbc:postgresql://" + serverName + ":" + port;
    conn = DriverManager.getConnection(url, username, password);

    pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database");
    ResultSet rs = pst.executeQuery();

    while (rs.next()) {
        databases.add(rs.getString(1));
    }
    rs.close();
    pst.close();

    databaseName = "teststrabon" + (int) (Math.random() * 10000);
    while (databases.contains(databaseName)) {
        databaseName += "0";
    }

    pst = conn.prepareStatement("CREATE DATABASE " + databaseName + " TEMPLATE " + databaseTemplateName);
    pst.executeUpdate();
    pst.close();
    conn.close();

    url = "jdbc:postgresql://" + serverName + ":" + port + "/" + databaseName;
    conn = DriverManager.getConnection(url, username, password);

    strabon = new Strabon(databaseName, username, password, Integer.parseInt(port), serverName, true);
}

From source file:com.sap.dirigible.repository.ext.db.DBUtils.java

/**
 * ResultSet current row to Content transformation
 * /*from  ww  w  .  j  a v a2s .  c o  m*/
 * @param resultSet
 * @return
 * @throws SQLException
 */
public static byte[] dbToData(ResultSet resultSet) throws SQLException {
    String data = resultSet.getString("DOC_CONTENT"); //$NON-NLS-1$
    return data.getBytes(Charset.defaultCharset());
}

From source file:local.Statistics.MostSellCars.java

/**
 * @param args the command line arguments
 *//* www  .  j  a  v a2s.c o  m*/
public static void carrosMasVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    //obtencion de datos
    ResultSet rs = gr.getgraficaautomas();

    try {
        String nameAuto;
        int quantitySales;
        Object[] fila = new Object[3];
        DefaultPieDataset data = new DefaultPieDataset();
        while (rs.next()) {

            nameAuto = rs.getString(3);
            quantitySales = rs.getInt(1);
            data.setValue(nameAuto, quantitySales);
        }
        JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MAS VENDIDOS", data, true, true, false);
        ChartFrame frame = new ChartFrame("Autos mas vendidos", chart);
        frame.pack();
        frame.setVisible(true);

        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(MostSellCars.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.ulyssis.ipp.snapshot.Event.java

public static Optional<Event> loadUnique(Connection connection, Class<? extends Event> eventType)
        throws SQLException, IOException {
    String statement = "SELECT \"id\", \"data\" FROM \"events\" WHERE \"type\" = ? AND \"removed\" = false";
    try (PreparedStatement stmt = connection.prepareStatement(statement)) {
        stmt.setString(1, eventType.getSimpleName());
        ResultSet result = stmt.executeQuery();
        if (result.next()) {
            String evString = result.getString("data");
            Event event = Serialization.getJsonMapper().readValue(evString, Event.class);
            event.id = result.getLong("id");
            event.removed = false;//  w  w w . j  a  v a2s. com
            return Optional.of(event);
        } else {
            return Optional.empty();
        }
    }
}

From source file:org.ulyssis.ipp.snapshot.Event.java

public static List<Event> loadAfter(Connection connection, Instant time, long id)
        throws SQLException, IOException {
    String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" "
            + "WHERE \"time\" > ? OR (\"time\" = ? AND \"id\" > ?) ORDER BY \"time\" ASC, \"id\" ASC";
    List<Event> events = new ArrayList<>();
    try (PreparedStatement stmt = connection.prepareStatement(statement)) {
        stmt.setTimestamp(1, Timestamp.from(time));
        stmt.setTimestamp(2, Timestamp.from(time));
        stmt.setLong(3, id);/*from  w  w w  . j ava  2 s.c om*/
        LOG.debug("Executing query: {}", stmt);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            String evString = rs.getString("data");
            Event event = Serialization.getJsonMapper().readValue(evString, Event.class);
            event.id = rs.getLong("id");
            event.removed = rs.getBoolean("removed");
            events.add(event);
        }
    }
    LOG.debug("Loaded {} events", events.size());
    return events;
}

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

public static void viewTable(Connection con, Proxy proxy) throws SQLException, IOException {
    Statement stmt = null;/* w ww.ja va 2s . c  o  m*/
    String query = "SELECT document_name, url FROM data_repository";

    try {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);

        if (rs.next()) {
            String documentName = null;
            java.net.URL url = null;

            documentName = rs.getString(1);

            // Retrieve the value as a URL object.
            url = rs.getURL(2);

            if (url != null) {

                // Retrieve the contents from the URL.
                URLConnection myURLConnection = url.openConnection(proxy);
                BufferedReader bReader = new BufferedReader(
                        new InputStreamReader(myURLConnection.getInputStream()));

                System.out.println("Document name: " + documentName);

                String pageContent = null;

                while ((pageContent = bReader.readLine()) != null) {
                    // Print the URL contents
                    System.out.println(pageContent);
                }
            } else {
                System.out.println("URL is null");
            }
        }
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } catch (IOException ioEx) {
        System.out.println("IOException caught: " + ioEx.toString());
    } catch (Exception ex) {
        System.out.println("Unexpected exception");
        ex.printStackTrace();
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}