View RSS Feed

Java Database

Processing ResultSet Objects

Rate this Entry
by , 03-10-2012 at 07:42 AM (881 Views)
Data that has been store in a ResultSet is accessed by a cursor. In ResultSet object, one row of data is pointed by the help of this cursor. In beginning, before 1st row the pointer gets positioned. Different methods are provided by the ResultSet objects so that to move the cursor.

Given code details the ResultSet object processing.
Java Code:
try {
    stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next()) {
        String coffeeName = rs.getString("COF_NAME");
        int supplierID = rs.getInt("SUP_ID");
        float price = rs.getFloat("PRICE");
        int sales = rs.getInt("SALES");
        int total = rs.getInt("TOTAL");
        System.out.println(
            coffeeName + "\t" + supplierID +
            "\t" + price + "\t" + sales +
            "\t" + total);
    }

Submit "Processing ResultSet Objects" to Facebook Submit "Processing ResultSet Objects" to Digg Submit "Processing ResultSet Objects" to del.icio.us Submit "Processing ResultSet Objects" to StumbleUpon Submit "Processing ResultSet Objects" to Google

Categories
JDBC

Comments