简体   繁体   English

使用Groovy Sql对象

[英]Using the Groovy Sql object

I'm trying to do some basic queries using the groovy.sql.Sql object, and I'm getting a SQLException that I can't seem to diagnose or make go away. 我正在尝试使用groovy.sql.Sql对象进行一些基本查询,并且得到了我似乎无法诊断或消失的SQLException。 I've reduced it to the simplest case, and I'm still seeing the problem. 我将其简化为最简单的情况,但仍然看到问题所在。 My code: 我的代码:

import groovy.sql.Sql

def bodyText
def sql = Sql.newInstance("jdbc:oracle:thin:@192.168.X.Y:1521:hostname",
                          "user", "passwd", "oracle.jdbc.OracleDriver")

sql.eachRow('select * from t_email_recipients') { row ->
  assert row.body != null
  java.sql.Clob clob = (java.sql.Clob) row.body
  bodyText = clob.getAsciiStream().getText()
  println bodyText
}

I had a version of this working earlier, but now all is seem to get are something like: 我早些时候有这个版本,但是现在看来一切都变得像这样:

Caught: java.sql.SQLException: Invalid column name
        at sqlTest$_run_closure1.doCall(sqlTest.groovy:14)
        at sqlTest.run(sqlTest.groovy:13)

Anyone have any ideas here? 有人在这里有什么想法吗? I'm using groovy 1.7.4, and jdk 1.6.0_12. 我正在使用groovy 1.7.4和jdk 1.6.0_12。

Given that the exception says Invalid column name and the only column you're accessing is body , my first guess is that there's no such column. 考虑到异常表明Invalid column name并且您要访问的唯一列是body ,我的第一个猜测是没有这样的列。 However you've indicated in the comments that there is such a column and moreover, you've asserted the presence of this column in the line preceding that which throws the exception 但是,您已经在注释中指出存在这样的一列,而且,您已经在抛出异常的行之前断言了该列的存在。

assert row.body != null

So it seems impossible that this code would throw this exception, so my best guess is that you've modified the code shown here is somehow different from the code that is actually throwing the exception - perhaps you didn't want to post the real code because it's too complex or for IP/privacy reasons. 因此该代码似乎不会引发该异常,因此,我最好的猜测是您修改了此处显示的代码与实际引发该异常的代码有所不同-也许您不想发布真实的代码因为它太复杂或出于IP /隐私原因。

If I'm right, van you check that this code really is functionally identical to the real code, because it seems impossible to me that this code would throw the given exception. 如果我是对的,请您检查一下此代码是否确实与实际代码相同,因为对我来说,这段代码似乎不会抛出给定的异常。

你可以用这样的东西

  clob?.asciiStream.text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM