Groovy Sql 获取所有列
我正在使用 Groovy Sql 来获取结果。这是我的 Linux 机器的输出。
%isql -U abc -P abc -S support
1> sp_configure 'number of open partitions'
2> go
Parameter Name Default Memory Used Config Value Run Value Unit Type
------------------------------ ----------- ----------- ------------ ------------ -------------------- ----------
number of open partitions 500 5201 5000 5000 number dynamic
(1 row affected)
(return status = 0)
1>
我正在使用常规代码
def sql = Sql.newInstance("jdbc:abc:sybase://harley:6011;DatabaseName=support;",dbuname,dbpassword,Driver)
sql.eachRow("sp_configure 'number of open partitions'"){ row ->
println row.run_value
}
,但它给了我
Exception in thread "main" java.sql.SQLSyntaxErrorException: [abc][Sybase JDBC Driver]Invalid column name: run_value
所以它说它无法获取指定的列,有没有办法可以获取结果并显示?
更新
我使用了以下代码
sql.eachRow("sp_configure 'number of open partitions'"){ row ->
println row
}
,它给了我
[Parameter Name:number of open partitions , Default: 500, Memory Used: 5201, Config Value: 5000, Run Value: 5000, Unit:number , Type:dynamic ]
如何获得运行值
? (因为它里面有一个空格)
row.Run Value
肯定不会工作
I am using Groovy Sql to fetch results. This is the output from my Linux box.
%isql -U abc -P abc -S support
1> sp_configure 'number of open partitions'
2> go
Parameter Name Default Memory Used Config Value Run Value Unit Type
------------------------------ ----------- ----------- ------------ ------------ -------------------- ----------
number of open partitions 500 5201 5000 5000 number dynamic
(1 row affected)
(return status = 0)
1>
I am using groovy code
def sql = Sql.newInstance("jdbc:abc:sybase://harley:6011;DatabaseName=support;",dbuname,dbpassword,Driver)
sql.eachRow("sp_configure 'number of open partitions'"){ row ->
println row.run_value
}
but it gives me
Exception in thread "main" java.sql.SQLSyntaxErrorException: [abc][Sybase JDBC Driver]Invalid column name: run_value
So it says it cannot get the speciied columns, is there a way it can fetch the result and display?
Update
I used the below code
sql.eachRow("sp_configure 'number of open partitions'"){ row ->
println row
}
and it gives me
[Parameter Name:number of open partitions , Default: 500, Memory Used: 5201, Config Value: 5000, Run Value: 5000, Unit:number , Type:dynamic ]
How can I get Run Value
? (since it has a space in it)
row.Run Value
will not work for sure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有效吗?查询元数据中的列名并通过索引获取值:
或者直接获取列
Does this work? Querying the meta-data for the column name and getting the value by index:
Or, to get the column directly
除了 @tim_yates 的回答之外,我想指出
row
有toRowResult()
方法。它允许简单地获取一行作为 Map。如果我们只需要列名或表宽度,则无需调用getMetadata()
。这段代码的作用完全相同,但看起来更清晰
Additioannly to @tim_yates's answer I'd like to note that
row
hastoRowResult()
method. It allows to get a row simply as a Map. No need to callgetMetadata()
if we need only column names or table width.This code doing absolutely the same but looks much more clear
另一种选择是 getAt(int)。在您的情况下,这将返回“运行值”:
row.getAt(-3)
Another alternative is getAt(int). In your case, this will return the 'Run Value':
row.getAt(-3)