tags:

views:

88

answers:

1

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. 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.

+1  A: 

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. 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.

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.

Don
Andrew B