Retrieve data example
You can fetch a distinct type as its underlying base type
or as a Java™ object, if the
mapping is defined in a custom type map. Using the previous example,
you can fetch the data as a Java object,
as shown in the following example:
java.util.Map customtypemap = conn.getTypeMap();
System.out.println("getTypeMap...ok");
if (customtypemap == null)
{
System.out.println("\n***ERROR: typemap is null!");
return;
}
customtypemap.put("mymoney", Class.forName("myMoney"));
...
String s = "select mymoney_col from distinct_tab order by 1";
try
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(s);
System.out.println("Fetching data ...");
int curRow = 0;
while (rs.next())
{
curRow++;
myMoney mymoneyret = (myMoney)rs.getObject("mymoney_col");
}
System.out.println("total rows expected: " + curRow);
stmt.close();
}
catch (SQLException e)
{
System.out.println("***ERROR: " + e.getErrorCode() + " " +
e.getMessage());
e.printStackTrace();
}
In this case, you use the getObject() method instead of the getBigDecimal() method to retrieve data.