Groovy SQL query to Excel output

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Groovy SQL query to Excel output

SharktheMark
Hopefully a simple problem...from a beginner: I'm trying to move directly from my sql.eachRow query into excel using the JExcel API.

sql.eachRow("Select * from subject") {row ->
                        int rownum = sheet.rows
                        sheet.addCell(new Label(0, rownum, row.ID))
                }

This will correctly return 2 items from the "ID" column, but the addCell() method crashes whenever it tries to pull more than one item from a query into excel. I can pull in one item without issue, so I'm pretty sure I've got the API correct. Am I missing something simple? I get the below error:

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.Integer, java.lang.Long)

Thanks much...
Reply | Threaded
Open this post in threaded view
|

Re: Groovy SQL query to Excel output

Dinko Srkoč
As far as I can see from the JExcel javadoc for jxl.write.Label, there
is no constructor that matches your arguments, just like error message
says. The closest is Label(int, int, String). Your 3rd argument,
row.ID (type is Long), is the culprit.

Cheers,
Dinko


On 16 June 2012 21:33, SharktheMark <[hidden email]> wrote:

> Hopefully a simple problem...from a beginner: I'm trying to move directly
> from my sql.eachRow query into excel using the JExcel API.
>
> sql.eachRow("Select * from subject") {row ->
>                        int rownum = sheet.rows
>                        sheet.addCell(new Label(0, rownum, row.ID))
>                }
>
> This will correctly return 2 items from the "ID" column, but the addCell()
> method crashes whenever it tries to pull more than one item from a query
> into excel. I can pull in one item without issue, so I'm pretty sure I've
> got the API correct. Am I missing something simple? I get the below error:
>
> groovy.lang.GroovyRuntimeException: Could not find matching constructor for:
> jxl.write.Label(java.lang.Integer, java.lang.Integer, java.lang.Long)
>
> Thanks much...
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/Groovy-SQL-query-to-Excel-output-tp5710206.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Groovy SQL query to Excel output

SharktheMark
Works beautifully now! Thanks much.

How did you know row.ID was Long? Is that a default in sql?
Reply | Threaded
Open this post in threaded view
|

Re: Groovy SQL query to Excel output

Dinko Srkoč
On 16 June 2012 23:32, SharktheMark <[hidden email]> wrote:
> Works beautifully now! Thanks much.
>
> How did you know row.ID was Long? Is that a default in sql?

No, it was the error message that gave row.ID's type away:
"Could not find matching constructor for:
jxl.write.Label(java.lang.Integer, java.lang.Integer, java.lang.Long)"

I matched that message with your code:
`new Label(0, rownum, row.ID)`

What the message says is that you tried to instantiate Label with two
Integers and a Long and Groovy couldn't find the appropriate
constructor.

Cheers,
Dinko

>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/Groovy-SQL-query-to-Excel-output-tp5710206p5710208.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email