使用RowSet
RowSet是JDBC2.0中提供的接口,Oracle对该接口有相应实现,其中很有用的是oracle.jdbc.rowset.OracleCachedRowSet。 OracleCachedRowSet实现了ResultSet中的所有方法,但与ResultSet不同的是,OracleCachedRowSet中的数据在Connection关闭后仍然有效。
oracle的rowset实现在http://otn.oracle.com/software/content.html的jdbc下载里有,名称是ocrs12.zip
示例代码:
//查询数据部分代码:
import javax.sql.RowSet;
import oracle.jdbc.rowset.OracleCachedRowSet;
Connection conn = DBUtil.getConnection();
PreparedStatement pst = null;
ResultSet rs = null;
try{
String sql=“select emp_code, real_name from t_employee where organ_id=?”;
pst = conn.preparedStatement(sql);
pst.setString(1, “101”);
rs = pst.executeQuery();
OracleCachedRowSet ors = newOracleCachedRowSet();
//将ResultSet中的数据封装到RowSet中
ors.populate(rs);
return ors;
}finally{
DBUtil.close(rs, pst, conn);
}
本文介绍了使用RowSet进行数据查询,重点提及JDBC2.0中的OracleCachedRowSet,它实现了ResultSet所有方法,且在Connection关闭后数据仍有效。还给出了其下载地址,同时展示了查询数据的示例代码。
917

被折叠的 条评论
为什么被折叠?



