【发布时间】:2011-10-19 02:12:46
【问题描述】:
处理 Java ResultSet 的最佳方法是什么?我正在创建一个桌面应用程序,它将使用 JDBC 连接到 Oracle 数据库。
但是,我在处理 ResultSet 时遇到了问题,因为我无法使用 for 循环进行比较。
// create a database connection object
DB db = new DB();
// get rows of my first table and second table
ResultSet firstRS = db.getMyFirstTable();
ResultSet seconRS = db.getSecondTable();
// compare the two tables
while(firstRS.next())
{
// get the row of my first table
String firstRSRow = firstRS.getString("col1");
while(secondRS.next())
{
// get the row of my second table
String secondRSRow = seconRS.getString("col1");
// compare row from first table to the row in second table
if(firstRSRow.startsWith(secondRSRow))
{
// do some processing here....
} // end if
} // end while
} // end while
我知道这可以通过 Hibernate 几行代码来完成,但我没有时间研究它。
我还从 apache 中找到了 commons DbUtils,但对于新手程序员来说这似乎很复杂。
是否有其他方法/工具/库/框架足够简单,可以从数据库中获取 ResultSet 并以简单直接的方式对其进行操作?
如果您能指导我访问一个包含有关 java 数据库连接的示例代码的网站,我将不胜感激。
非常感谢您的支持。
【问题讨论】:
标签: java database oracle hibernate jdbc