在jython中获取完整的sql查询
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您的另一个问题:要显示您不知道查询返回多少列的查询结果,您必须使用元数据(最好)或在 getString(i) 引发异常时迭代并完成。
如果您知道返回了多少列,如
cnt(*)
情况,您可以简单地使用rs.getString(1)
:使用
cnt(*)< /code> 您可以使用
getInt(1)
,或使用AS
命名列:并使用
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 users.getString(1)
:With
cnt(*)
you can usegetInt(1)
, or name column usingAS
: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