Example usage for java.sql ResultSet getObject

List of usage examples for java.sql ResultSet getObject

Introduction

In this page you can find the example usage for java.sql ResultSet getObject.

Prototype

Object getObject(String columnLabel) throws SQLException;

Source Link

Document

Gets the value of the designated column in the current row of this ResultSet object as an Object in the Java programming language.

Usage

From source file:net.orpiske.ssps.common.db.CountRsHandler.java

@Override
public Integer handle(ResultSet rs) throws SQLException {
    Integer dto = null;//from   w  ww.  ja  v a 2  s .  c o  m

    // No records to handle :O
    if (!rs.next()) {
        return null;
    }

    ResultSetMetaData meta = rs.getMetaData();

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Object value = rs.getObject(i);

        try {
            if (value instanceof Integer) {
                dto = (Integer) value;
            }

        } catch (Exception e) {
            throw new SQLException("Unable to set/retrieve count value", e);
        }
    }

    return dto;
}

From source file:com.orientechnologies.orient.jdbc.spring.IoTatWorkThread.java

public void run() {
    try {/*w  ww. j  ava  2s.  co m*/
        PreparedStatement queryPrepStatement = connection
                .prepareStatement("SELECT FROM OGraphVertex WHERE name = ?");
        queryPrepStatement.setString(1, ROOT_VERTEX_NAME);
        ResultSet rs = queryPrepStatement.executeQuery();

        Assert.assertTrue(NAME + "There is no vertex with name " + ROOT_VERTEX_NAME, rs.first());
        //the RID is always the first element in the RS
        Object vertexId = rs.getObject(1);
        OrientGraph g = connection.unwrap(OrientGraph.class);
        Vertex v = g.getVertex(vertexId);

        Iterator<Edge> categories = v.getEdges(Direction.OUT, "category").iterator();
        Edge categoryEdge;
        Vertex aggregationV = null;
        while (categories.hasNext() && aggregationV == null) {
            categoryEdge = categories.next();
            if (categoryEdge.getVertex(Direction.IN).getProperty("name").equals("Aggregation"))
                aggregationV = categoryEdge.getVertex(Direction.IN);
        }
        Assert.assertNotNull("Missing aggregation category", aggregationV);
        Iterator<Edge> containmentRels = aggregationV.getEdges(Direction.OUT, CONTAINMENT_RELATION_EDGE)
                .iterator();
        Assert.assertTrue(NAME + "There is no edge with label '" + CONTAINMENT_RELATION_EDGE + "' coming from "
                + v.toString(), containmentRels.hasNext());

        String prefix = NAME + "Values:: ";
        StringBuilder textToBePrinted = new StringBuilder(prefix);
        Edge currentRel;
        while (containmentRels.hasNext()) {
            currentRel = containmentRels.next();
            if (textToBePrinted.length() == prefix.length())
                textToBePrinted.append(currentRel.getVertex(Direction.IN).getProperty("name").toString());
            else
                textToBePrinted
                        .append(", " + currentRel.getVertex(Direction.IN).getProperty("name").toString());
        }
        System.out.println(textToBePrinted);
    } catch (SQLException e) {
        e.printStackTrace();
        Assert.fail();
    }

}

From source file:com.netspective.axiom.sql.ResultSetUtils.java

public Set getResultSetRowsFirstColumnAsSet(ResultSet rs) throws SQLException {
    Set result = new HashSet();
    while (rs.next())
        result.add(rs.getObject(1));
    return result;
}

From source file:guru.bubl.module.neo4j_graph_manipulator.graph.FriendlyResourceNeo4j.java

@Override
public Node getNode() {
    if (null == node) {
        node = NoEx.wrap(() -> {//ww  w  .  j  a  v a 2 s.co m
            ResultSet rs = connection.createStatement().executeQuery(queryPrefix() + "return n");
            rs.next();
            return (Node) rs.getObject("n");
        }).get();
    }
    return node;
}

From source file:guru.bubl.module.neo4j_graph_manipulator.graph.Neo4jFriendlyResource.java

@Override
public Node getNode() {
    if (null == node) {
        node = NoExRun.wrap(() -> {//from   w ww.j  a v a 2  s  . c  o  m
            ResultSet rs = connection.createStatement().executeQuery(queryPrefix() + "return n");
            rs.next();
            return (Node) rs.getObject("n");
        }).get();
    }
    return node;
}

From source file:de.gmorling.scriptabledataset.ScriptableDataSetTest.java

private void assertNextRow(ResultSet rs, int expectedInt, String expectedString, Date expectedDate)
        throws SQLException {

    if (!rs.next())
        fail("Data set should have a row.");

    assertEquals(expectedInt, rs.getObject(1));
    assertEquals(expectedString, rs.getObject(2));
    assertEquals(DateUtils.truncate(expectedDate, Calendar.DATE),
            DateUtils.truncate(rs.getObject(3), Calendar.DATE));
}

From source file:models.CategoriaDAO.java

public String obtenerCategoriasJSON() {
    Producto producto = new Producto();
    String json = "[";
    try {/*from w w w  . j  a  v a2  s .  c  o  m*/
        conn = conexion.getConexion();
        String query = "SELECT * FROM categoria ORDER BY nombre ASC";
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        JSONObject js = new JSONObject();
        int contador = 0;

        while (rs.next()) {
            if (contador != 0) {
                json = json + ",";
            }
            Object id = rs.getObject("id");
            Object nombre = rs.getObject("nombre");
            try {
                js.put("id", id);
                js.put("nombre", nombre);
                json = json + js.toString();

            } catch (JSONException ex) {
                Logger.getLogger(Producto.class.getName()).log(Level.SEVERE, null, ex);
            }
            contador++;
        }

        json = json + "]";

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception e) {
            /* ignored */ }
    }

    return json;
}

From source file:models.PlataformaDAO.java

public String obtenerPlataformasJSON() {
    Producto producto = new Producto();
    String json = "[";
    try {// w  w  w . ja  va2 s  .c  o m
        conn = conexion.getConexion();
        String query = "SELECT * FROM plataforma ORDER BY nombre ASC";
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        JSONObject js = new JSONObject();
        int contador = 0;

        while (rs.next()) {
            if (contador != 0) {
                json = json + ",";
            }
            Object id = rs.getObject("id");
            Object nombre = rs.getObject("nombre");
            try {
                js.put("id", id);
                js.put("nombre", nombre);
                json = json + js.toString();

            } catch (JSONException ex) {
                Logger.getLogger(Producto.class.getName()).log(Level.SEVERE, null, ex);
            }
            contador++;
        }

        json = json + "]";

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
        } catch (Exception e) {
            /* ignored */ }
    }

    return json;
}

From source file:com.openddal.test.BaseTestCase.java

private static String[] getData(ResultSet rs, int len) throws SQLException {
    String[] data = new String[len];
    for (int i = 0; i < len; i++) {
        data[i] = rs.getString(i + 1);//w  ww .  java2 s  .com
        // just check if it works
        rs.getObject(i + 1);
    }
    return data;
}

From source file:com.teradata.benchto.driver.execution.QueryExecutionDriver.java

private void logRow(int rowNumber, ResultSet resultSet) throws SQLException {
    ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
    StringJoiner joiner = new StringJoiner("; ", "[", "]");
    for (int i = 1; i <= resultSetMetaData.getColumnCount(); ++i) {
        joiner.add(resultSetMetaData.getColumnName(i) + ": " + resultSet.getObject(i));
    }/*from   www  .  j a v  a 2 s.com*/

    LOG.info("Row: " + rowNumber + ", column values: " + joiner.toString());
}