Java Reference
In-Depth Information
ResultSet rs = stmt.executeQuery(query);
System.out.println("Name\tDescription\tQty\tCost");
while (rs.next()) {
System.out.print(rs.getString("Name")+"\t");
System.out.print(rs.getString("Description")+"\t");
System.out.print(rs.getInt("Qty")+"\t");
System.out.println(rs.getFloat("Cost"));
}
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
ResultSet rows are retrieved in sequence from the top row down as the cursor moves
down one row with each successive call to ne xt().
A cursor remains valid until the ResultSet object or its parent Statement object is
closed.
Column names used as input to ResultSet getter methods are case
insensitive.
Note
Data is retrieved from a ResultSet using getter methods that reference the column
containing the data. The ResultSet getter methods provide for data-type specific
retrieval of column values from the current row. Within each row, column values may
be retrieved in any order.
The getter methods the ResultSet object provides are listed in Table 4-3 . Each getter
method has two variants: one that references the column by name and one by
column number. For brevity, only one variant of each is listed in Table 4 -3 .
Caution Columns are numbered from left to right, starting with column 1, not
column 0.
Table 4-3: ResultSet getter Methods
Data Type
Method
BigDecimal
getBigDecimal(String columnName, int scale)
Search WWH ::




Custom Search