在jython中获取完整的sql查询

发布于 2024-08-27 08:34:27 字数 328 浏览 3 评论 0原文

result=sqlstring.executeQuery("select distinct table_name,owner from all_tables ")

rs.append(str(i)+' , '+result.getString("table_name")+' , '+result.getString("owner"))

如果我想显示查询 select * from all_tables' select count(*) from all_tables'

我怎样才能获得要显示的输出。请推荐谢谢

result=sqlstring.executeQuery("select distinct table_name,owner from all_tables ")

rs.append(str(i)+' , '+result.getString("table_name")+' , '+result.getString("owner"))

If i want to display the query select * from all_tables or ' select count(*) from all_tables'

how can i get the output to display . Please suggest thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓酥 2024-09-03 08:34:27

正如您的另一个问题:要显示您不知道查询返回多少列的查询结果,您必须使用元数据(最好)或在 getString(i) 引发异常时迭代并完成。

如果您知道返回了多少列,如 cnt(*) 情况,您可以简单地使用 rs.getString(1)

rs = conn.executeQuery("select count(*) from my_table")
while (rs.next()):
   cnt = rs.getString(1)

使用 cnt(*)< /code> 您可以使用 getInt(1),或使用 AS 命名列:

select count(*) as rec_cnt from my_table

并使用 rec_cnt = rs.getInt('rec_cnt') 获取它代码>.

如果您使用 JDBC,您应该阅读相关内容并熟悉 Java 文档,例如: 记录集

As in another your question: to show query results where you do not know how many columns query returns you must use metadata (best) or iterate and finish when getString(i) raises exception.

If you know how many columns is returned, as in cnt(*) case you can simply use rs.getString(1):

rs = conn.executeQuery("select count(*) from my_table")
while (rs.next()):
   cnt = rs.getString(1)

With cnt(*) you can use getInt(1), or name column using AS:

select count(*) as rec_cnt from my_table

and get it using rec_cnt = rs.getInt('rec_cnt').

If you use JDBC you should read something about it and get familiar with Java doc like: RecordSet

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文