读取 Java 结果集中的整行
我知道有类似的问题,但我没有在任何地方找到任何答案。由于某种原因,ResultSet 没有将整行读取到 String 或类似对象的功能,因此需要制定一些棘手的解决方法来读取整行,并且它总是涉及逐列处理。
问题是 - 执行此操作的首选方法是什么?
示例查询 - SELECT a,b,c,d,e FROM table WHERE this=that
。
我想将此查询的每一行添加到 List<字符串>并在完成后返回列表。
目前我能想到的就是读取每一列,将其连接到一个字符串,然后将字符串添加到列表中,对于每一行都是如此。
问题是,恕我直言,这弥补了相当多的代码,因为它可以单独在 ResultSet 中完成。
有什么想法/建议吗?
I know there are similar questions to this one, but I haven't found any answer anywhere. For some reason ResultSet has no function to read the full row to a String or similar object, so there's a need to make up tricky workarounds to read full rows and it always involves column-by-column processing.
The question is - what would be the preferred way to do this?
An example query - SELECT a,b,c,d,e FROM table WHERE this=that
.
I want to add each row of this query to a List< String> and return the List when it's completed.
Currently all I can think of is reading each column, concatenating it to a String and then adding the String to the List, and this for each row.
The problem is that IMHO this makes up for quite excessive code when it could be done in ResultSet alone.
Any ideas/suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 SQL 连接以下结果:你喜欢这样:
那么在你的结果集中你只有一列需要处理。
You can use SQL to concatenate the results for you like this:
Then in your resultset you have only a single column to deal with.