如何以编程方式从没有数据库的自定义数据创建Java ResultSet [英] How to programmatically create a Java ResultSet from custom data with no database

查看:54
本文介绍了如何以编程方式从没有数据库的自定义数据创建Java ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些现有的代码,可以接受 java.sql.ResultSet ,其中包含从Oracle数据库检索的信息.我现在想重用此代码,但我想向它传递一个 ResultSet 对象,该对象是我从一些不属于任何数据库的内存数据中创建的.是否可以使用现有的Java框架类? ResultSet 有很多方法,因此即使我可以针对自己的具体情况忽略大多数方法,为此实现自己的类也显得有些过分.

I have some existing code that accepts a java.sql.ResultSet that contains info retrieved from an Oracle database. I would now like to reuse this code, but I'd like to pass it a ResultSet object that I create myself from some in-memory data that is not affiliated with any database. Is there an existing Java framework class that I can use for this? ResultSet has tons of methods, so implementing my own class for this seemed like overkill, even though I could ignore most of the methods for my specific case.

我正在考虑遵循旧的Microsoft ADO记录集对象的方式,可以在其中创建字段,然后为每个字段填充行数据.这似乎是一个容易探究的问题,但我一直找不到任何好的指针.

I was thinking of something along the lines of the old Microsoft ADO recordset object, where I could create the fields and then populate the row data for each field. This seemed like an easily googlable question, but I've been unable to find any good pointers.

推荐答案

  • 创建您自己的 AbstractResultSet 类,该类(如AbstractQueue)通过抛出UnsupportedOperationException来实现所有方法(Eclipse会在一瞬间自动生成这些方法).
  • 现在扩展 AbstractResultSet .子类只能覆盖您想要实现的方法.
    • Create your own AbstractResultSet class, one that (like AbstractQueue) implements all methods by throwing UnsupportedOperationException (Eclipse autogenerates these methods in a split second).
    • Now extend AbstractResultSet. The subclass can override only the methods you're interested in implementing.
    • 这篇关于如何以编程方式从没有数据库的自定义数据创建Java ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆