gpt4 book ai didi

java - 来自数据库的行作为字符串 (JDBC)

转载 作者:行者123 更新时间:2023-11-29 09:51:16 25 4
gpt4 key购买 nike

是否有直接的方法从 ResultSet 中获取一行中的所有元素作为字符串? JDBC

最佳答案

您可以使用来自 Apache commons, DbutilsBasicRowProcessor

ResultSet rs = ....
RowProcessor rp = new BasicRowProcessor();
Map m = rp.toMap( rs );

String s = m.toString();

然后您将拥有:

{ id = 1, name = Oscar, lastName = Reyes }

如果你想去掉 columNames:

String s = m.values().toString();

关于java - 来自数据库的行作为字符串 (JDBC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1633991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com