要检索 GBase 8s 不透明类型,必须使用 ResultSet.getObject()。GBase 8s JDBC Driver 根据
您提供的自定义类型将数据转换为 Java™ 对象。使用前面示例的 charattrUDT 类型,可以
获取此不透明数据,如下所示:
String s = "select int_col, charattr_col from charattr_tab order by 1";
System.out.println(s);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(s);
System.out.println("execute...ok");
System.out.println("Fetching data ...");
int curRow = 0;
while (rs.next())
{
curRow++;
GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 191 -
System.out.println("currentrow=" + curRow + " : ");
int intret = rs.getInt("int_col");
System.out.println(" int_col " + intret);
charattrUDT charattrret = (charattrUDT)rs.getObject("charattr_col");
System.out.print(" charattr_col ");
if (curRow == 2 || curRow == 6)
{
if (rs.wasNull())
System.out.println("
else
System.out.println("***ERROR: " + charattrret);
}
else
System.out.println(charattrret+"");
} //while
System.out.println("total rows expected: " + curRow);
stmt.close();