File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Groovy and the fly likes helping with groovy and sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "helping with groovy and sql" Watch "helping with groovy and sql" New topic

helping with groovy and sql

Mike Dezarre

Joined: Feb 05, 2013
Posts: 1
hi guys, can you help me with the commenting on this code snippet -> codelines with //??? i dont know what is happening here

chris webster

Joined: Mar 01, 2009
Posts: 2292

Mike Dezarre wrote:hi guys, can you help me with the commenting on this code snippet -> codelines with //??? i dont know what is happening here...

From looking at the groovy.sq.Sql API documentation, I'd say the SQL is saying it wants to fetch a column called "WERT" (German for "value" - not a good choice for a column name) from the table ad_user_env for a given user_ref.
Then the call to sql.firstRow provides the required user reference (although the firstRow() docs seem to suggest that bind values should be provided as a list).
Anyway, the call to firstRow is supposed to fetch the "WERT" value for the required row in the database and store it in the result variable. I think that's what the ".wert" bit after the firstRow() call does - it gets the "wert" value that was returned in the firstRow query results. But I don't know if it will work like this, as the column name is UPPER in the SQL but lower here.

This is basically the same kind of thing, but this time the SQL SELECT includes several bind variables, so you need to provide several values as a list in your firstRow() call.
So I think szenario() returns the value we found in the first SQL query and then the svr() function uses that value in this query, but I'm not sure.
Anyway, it seems like a complicated way of doing something you could probably do more easily in a single query. And to be honest, you should probably find a better tutorial if this is somebody else's code that you're trying to learn from.

Meanwhile, it sounds like you might need to brush up on basic SQL, and always check the API docs if you're not sure what a method like firstRow() does.

No more Blub for me, thank you, Vicar.
I agree. Here's the link:
subject: helping with groovy and sql
It's not a secret anymore!