Java中的大量数据查询计算机等级考试

文章作者 100test 发表时间 2010:02:02 15:57:28
来源 100Test.Com百考试题网


  问题描述:在通常的三层构架下,客户通过Browser请求Web服务器查询数据库,而查询结果是上千条甚至是上百万条记录,要求查询结果传送到客户端浏览器并分页显示。

  考虑因素:

  1. Web服务器的资源消耗,包括:内存(用来存储查询结果),数据库相关资源(数据库连接对象,ResultSet对象等等);

  2. DB服务器资源的消耗,包括游标,会话等等。

  3. 网络开销,包括与数据库建立会话,传输查询结果等等。

  JDBC中的几个重要Class:

  A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

  ResultSet是直接在数据库上建立游标,然后通过ResultSet的行位置定位接口来获得指定行位置的记录。当用户通过get方法获取具体纪录的内容时,ResultSet才从数据库把所需数据读到客户端。

  Oracle的ResultSet实现似乎会在本地缓存用户读取过的数据,导致内存消耗会随读取数据的增加而增加,这样,如果一次查询并读取海量数据,即使读出数据后马上丢弃(比如直接写入文件),内存消耗也会随查询结果的增加而递增。

  The RowSet interface extends the standard java.sql.ResultSet interface. A RowSet object may make a connection with a data source and maintain that connection throughout its life cycle, in which case it is called a connected rowset. A rowset may also make a connection with a data source, get data from it, and then close the connection. Such a rowset is called a disconnected rowset. A disconnected rowset may make changes to its data while it is disconnected and then send the changes back to the original source of the data, but it must reestablish a connection to do so.

  RowSet是JDBC2.0中提供的接口,Oracle对该接口有相应实现,其中很有用的是 oracle.jdbc.rowset.OracleCachedRowSet。 OracleCachedRowSet实现了ResultSet中的所有方法,但与ResultSet不同的是,OracleCachedRowSet中的数据在Connection关闭后仍然有效。


相关文章


Java中的TCP_UDP网络通信编程计算机等级考试
Java防止浏览器直接打开下载的文件计算机等级考试
Java将gif格式图片转为jpg格式计算机等级考试
RAR和JAR文件识别JAR文件安装方法计算机等级考试
Java中的大量数据查询计算机等级考试
C 中的强制类型转换计算机等级考试
STL容器迭代过程中删除元素技巧计算机等级考试
利用Socket实现C 与Flex通信计算机等级考试
vc6中使用ADO的问题计算机等级考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛