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:database.DBAccountManager.java

public static String getEntry(String table, String id, String type) throws SQLException {
    ResultSet rs = Connector
            .selectQuery("SELECT " + type + " FROM " + Sql.DB + "." + table + " WHERE id = '" + id + "';");
    rs.next();/*ww  w .  j  a v  a 2  s.c om*/
    return rs.getString(type);
}

From source file:com.flexive.core.search.DataSelector.java

/**
 * Decode the binary value that was previously selected with
 * {@link #selectBinary(String)} at the given result set position.
 *
 * @param rs    the result set/*  w  ww .ja  v a2 s.c  om*/
 * @param pos   the column index
 * @return      the decoded binary
 * @throws SQLException on database errors
 */
public static BinaryDescriptor decodeBinary(ResultSet rs, int pos) throws SQLException {
    final String encodedBinary = rs.getString(pos);
    if (rs.wasNull()) {
        return new BinaryDescriptor();
    }
    final String[] values = StringUtils.split(encodedBinary, BINARY_DELIM);
    return new BinaryDescriptor(CacheAdmin.getStreamServers(),
            java.lang.Long.parseLong(getBinaryValue(values, "ID")), 1, 1,
            java.lang.Long.parseLong(getBinaryValue(values, "CREATED_AT")), getBinaryValue(values, "NAME"),
            java.lang.Long.parseLong(getBinaryValue(values, "BLOBSIZE")), null,
            getBinaryValue(values, "MIMETYPE"), "1".equals(getBinaryValue(values, "ISIMAGE")),
            Double.parseDouble(getBinaryValue(values, "RESOLUTION")),
            java.lang.Integer.parseInt(getBinaryValue(values, "WIDTH")),
            java.lang.Integer.parseInt(getBinaryValue(values, "HEIGHT")), getBinaryValue(values, "MD5SUM"));
}

From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java

private static List<String> getCatalogs(DatabaseMetaData dbmd) throws SQLException {
    final List<String> catalogNames = new LinkedList<String>();
    final ResultSet rs = dbmd.getCatalogs();
    while (rs.next()) {
        catalogNames.add(rs.getString(1));
    }//from  w w  w. java  2s. c  o m
    rs.close();
    return catalogNames;
}

From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java

public static List<String> getTableTypes(DatabaseMetaData dbmd) throws SQLException {
    final List<String> tableTypes = new LinkedList<String>();
    final ResultSet rs = dbmd.getTableTypes();
    while (rs.next()) {
        tableTypes.add(rs.getString(1));
    }/*from  www  .  ja  v  a 2 s  .c  o m*/
    rs.close();
    return tableTypes;
}

From source file:com.chiralbehaviors.CoRE.kernel.KernelUtil.java

static void alterTriggers(Connection connection, boolean enable) throws SQLException {
    for (String table : new String[] { "ruleform.agency", "ruleform.product", "ruleform.location" }) {
        String query = String.format("ALTER TABLE %s %s TRIGGER ALL", table, enable ? "ENABLE" : "DISABLE");
        connection.createStatement().execute(query);
    }/*w  w  w  .j  a v  a2 s  .  c  o  m*/
    ResultSet r = connection.createStatement().executeQuery(KernelUtil.SELECT_TABLE);
    while (r.next()) {
        String table = r.getString("name");
        String query = String.format("ALTER TABLE %s %s TRIGGER ALL", table, enable ? "ENABLE" : "DISABLE");
        connection.createStatement().execute(query);
    }
    r.close();
}

From source file:com.chiralbehaviors.CoRE.kernel.KernelUtil.java

public static void clear(EntityManager em) throws SQLException {
    Connection connection = em.unwrap(Connection.class);
    connection.setAutoCommit(false);/* w ww . j  ava  2s .  c  o m*/
    alterTriggers(connection, false);
    ResultSet r = connection.createStatement().executeQuery(KernelUtil.SELECT_TABLE);
    while (r.next()) {
        String table = r.getString("name");
        String query = String.format("DELETE FROM %s", table);
        connection.createStatement().execute(query);
    }
    r.close();
    alterTriggers(connection, true);
    CACHED_KERNEL.set(null);
    connection.commit();
}

From source file:local.Statistics.LessSellCars.java

/**
 * @param args the command line arguments
 *//*from w  w  w.  j  av  a2 s  . c  o  m*/
public static void carrosMenosVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    ResultSet rs = gr.getgraficaautomas();
    try {
        String nameAuto;
        int quantitySales;
        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 MENOS VENDIDOS", data, true, true,
                false);
        ChartFrame frame = new ChartFrame("Autos menos vendidos", chart);
        frame.pack();
        frame.setVisible(true);
        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(LessSellCars.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.cloudslang.content.database.utils.Format.java

/**
 * Returns column number col from the current result set and returns as string
 *
 * @param rs                   the result set on current row
 * @param col                  1-indexed column number
 * @param checkNullTermination perform the null termination check on a string (eg. netcool)
 * @return/*from   w  w w  .  ja  v a  2  s  .c om*/
 * @throws SQLException
 */
private static String getColumn(ResultSet rs, int col, boolean checkNullTermination) throws SQLException {
    final String value = rs.getString(col);
    if (value == null) {
        return "null";
    }
    if (checkNullTermination) {
        return processNullTerminatedString(value);
    }
    return value;
}

From source file:local.Statistics.LessSellRepuesto.java

/**
 * @param args the command line arguments
 *//*from  w  w w .  j  a v  a 2  s. c o  m*/
public static void repuestosMenosVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    //obtencion de datos
    ResultSet rs = gr.getgraficarepuestomen();
    try {
        String nameAuto;
        int quantitySales;
        DefaultPieDataset data = new DefaultPieDataset();
        while (rs.next()) {
            nameAuto = rs.getString(3);
            quantitySales = rs.getInt(1);
            data.setValue(nameAuto, quantitySales);
        }
        JFreeChart chart = ChartFactory.createPieChart("GRAFICAS REPUESTO MENOS VENDIDOS", data, true, true,
                false);
        ChartFrame frame = new ChartFrame("Repuestos menos vendidos", chart);
        frame.pack();
        frame.setVisible(true);
        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(LessSellRepuesto.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:eu.databata.engine.util.PropagatorTableExport.java

private static void exportTablesData(JdbcTemplate jdbcTemplate, String delimiter, String tableNamePattern) {
    try {//from  w ww . java2s . c om
        System.out.println("Trying to load tables from metadata");
        Connection connection = jdbcTemplate.getDataSource().getConnection();
        ResultSet tables = connection.getMetaData().getTables(null, null, tableNamePattern,
                new String[] { "TABLE" });
        while (tables.next()) {
            System.out.println("Exporting data from " + tables.getString("TABLE_NAME"));
            exportData(jdbcTemplate, tables.getString("TABLE_NAME"), delimiter);
        }
    } catch (SQLException e) {
        System.out.println("\nError when trying to get table names from DB.");
    }
}