Groovy Sql获取所有列
16lz
2021-01-22
I am using Groovy Sql to fetch results. This is the output from my Linux box.
我正在使用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>
I am using groovy code
我正在使用groovy代码
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)
我怎样才能获得Run Value? (因为里面有空格)
row.Run Value
will not work for sure
row.Run值无法确定
2 个解决方案
#1
3
Does this work? Querying the meta-data for the column name and getting the value by index:
这有用吗?查询列名的元数据并按索引获取值:
sql.eachRow("sp_configure 'number of open partitions'"){ row ->
(1..row.getMetaData().columnCount).each {
println "${row.metaData().getColumnName( it )} = ${row[ it ]}"
}
}
Or, to get the column directly
或者,直接获取列
row.'Run Value'
更多相关文章
- postgresql 数组 多了引号 空格处理
- sql2005指定字段插入空格。
- 在arcpy中删除或删除表的代码是什么?
- iBatis中sqlmap resultclass="java.lang.Integer",在代码中如何
- 已有SQLSERVER表如何生成其代码?
- PHP执行.SQL文件的实例代码分享
- 要在SQL数据库中根据身份证号码查询出性别(有15位的,也有18位的),怎
- 一条牛B的SQL抵了我300多行的程序代码
- Android中RecyclerView的item中控件的点击事件添加删除一行、上