How to programmatically create a Java ResultSet from custom data with no database

后端 未结 7 1899
渐次进展
渐次进展 2020-12-17 08:53

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

相关标签:
7条回答
  • 2020-12-17 09:26

    My first option would be to refactor the code so that it takes List<Map<String,Object>> or something appropriate (that is, List<Map<String,Object>> if the data being moved around has no real structure or fully-typed objects if it does have structure).

    If that's not feasible or time efficient, the "fun" hack is to query an in-memory H2 database to get a ResultSet. If you don't find a reasonable stub for ResultSet you can easily instantiate, it might be quicker than rolling your own (pull the jar in, write 20 lines of code for creating the db and populating a table).

    0 讨论(0)
提交回复
热议问题