[groovy-user] groovy+sql not-working example

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

[groovy-user] groovy+sql not-working example

Željko Krstić
Hay all
I find that sql+groovy "call stored oracle procedure" doesn't work
(http://groovy.codehaus.org/Groovy+SQL). What is this ${Sql.INTEGER} ? It
should be parameter used for returning value(s), but groovy doesn't recognize
it as java.lang.Class field. I can find it in
ojdbc14_g.jar\oracle\jdbc\OracleTypes ..
Can someone pass me working example of Sql.call methode or help me understand
why this doesnt't work?
Thanks in advance

Here's source:

import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes

driver = oracle.jdbc.driver.OracleDriver
Connection conn =
DriverManager.getConnection('jdbc:oracle:thin:scott/tiger@localhost:1521:XE');

/*
 *
 * Here we call a procedural block with a closure.
 * ${Sql.INTEGER} and ${Sql.VARCHAR} are out parameters
 * which are passed to the closure.
 *
 */
Sql sql = new Sql(conn);
def a="foo";
String foo = "x";
println "${a}=${a}"
undefinedVar = null
println """
--Simple demonstration of call with closure.
--Closure is called once with all returned values.
"""
sql.call("begin ${Sql.INTEGER}:=20; ${Sql.VARCHAR}:='hello
world';end;"){answer,string| println "number=[${answer}] string=[${string}]"
   println "answer is a ${answer.class}";
   println "string is a ${string.class}";
   answer += 1;
   println "now number=${answer}"
   println """[${string.replaceAll("o","O")}]"""
}


Here's output:

Exception thrown: groovy.lang.MissingFieldException: No such field: INTEGER for
class: java.lang.Class

groovy.lang.MissingFieldException: No such field: INTEGER for class:
java.lang.Class
        at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:1074)
        at groovy.lang.MetaClassImpl.getStaticProperty(MetaClassImpl.java:1308)
        at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:707)
        at org.codehaus.groovy.runtime.Invoker.getProperty(Invoker.java:727)
        at
org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:206)
        at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:295)
        at Script17.run(Script17:26)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:521)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:462)
        at gjdk.groovy.lang.GroovyShell_GroovyReflector.invoke(Unknown Source)
        at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
        at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
        at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
        at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
        at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy:500)
        at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
        at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
        at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
        at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
        at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy)
        at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
        at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
        at groovy.lang.Closure.call(Closure.java:176)
        at groovy.lang.Closure.call(Closure.java:171)
        at groovy.lang.Closure.run(Closure.java:252)
        at java.lang.Thread.run(Thread.java:595)



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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

RE: [groovy-user] groovy+sql not-working example

Dierk König
Hi,

this has nothing to do with Groovy Sql support as such but
with a bug I posted recently
 Sql
is recognized as being of java.lang.class instead of Sql.class.

As a workaround, use
 Sql.class
explicitly instead.

cheers
Mittie

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: Freitag, 2. Juni 2006 12:53
> To: [hidden email]
> Subject: [groovy-user] groovy+sql not-working example
>
>
> Hay all
> I find that sql+groovy "call stored oracle procedure" doesn't work
> (http://groovy.codehaus.org/Groovy+SQL). What is this ${Sql.INTEGER} ? It
> should be parameter used for returning value(s), but groovy
> doesn't recognize
> it as java.lang.Class field. I can find it in
> ojdbc14_g.jar\oracle\jdbc\OracleTypes ..
> Can someone pass me working example of Sql.call methode or help
> me understand
> why this doesnt't work?
> Thanks in advance
>
> Here's source:
>
> import java.sql.Connection
> import java.sql.DriverManager
> import javax.sql.DataSource
> import groovy.sql.Sql
> import oracle.jdbc.driver.OracleTypes
>
> driver = oracle.jdbc.driver.OracleDriver
> Connection conn =
> DriverManager.getConnection('jdbc:oracle:thin:scott/tiger@localhos
> t:1521:XE');
>
> /*
>  *
>  * Here we call a procedural block with a closure.
>  * ${Sql.INTEGER} and ${Sql.VARCHAR} are out parameters
>  * which are passed to the closure.
>  *
>  */
> Sql sql = new Sql(conn);
> def a="foo";
> String foo = "x";
> println "${a}=${a}"
> undefinedVar = null
> println """
> --Simple demonstration of call with closure.
> --Closure is called once with all returned values.
> """
> sql.call("begin ${Sql.INTEGER}:=20; ${Sql.VARCHAR}:='hello
> world';end;"){answer,string| println "number=[${answer}]
> string=[${string}]"
>    println "answer is a ${answer.class}";
>    println "string is a ${string.class}";
>    answer += 1;
>    println "now number=${answer}"
>    println """[${string.replaceAll("o","O")}]"""
> }
>
>
> Here's output:
>
> Exception thrown: groovy.lang.MissingFieldException: No such
> field: INTEGER for
> class: java.lang.Class
>
> groovy.lang.MissingFieldException: No such field: INTEGER for class:
> java.lang.Class
> at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:1074)
> at
> groovy.lang.MetaClassImpl.getStaticProperty(MetaClassImpl.java:1308)
> at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:707)
> at org.codehaus.groovy.runtime.Invoker.getProperty(Invoker.java:727)
> at
> org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelpe
> r.java:206)
> at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(Scri
> ptBytecodeAdapter.java:295)
> at Script17.run(Script17:26)
> at groovy.lang.GroovyShell.evaluate(GroovyShell.java:521)
> at groovy.lang.GroovyShell.evaluate(GroovyShell.java:462)
> at
> gjdk.groovy.lang.GroovyShell_GroovyReflector.invoke(Unknown Source)
> at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaCla
> ssHelper.java:636)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelp
> er.java:104)
> at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(Scr
> iptBytecodeAdapter.java:85)
> at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy:500)
> at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAc
> cessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(Reflection
> MetaMethod.java:67)
> at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaCla
> ssHelper.java:636)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelp
> er.java:104)
> at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(Scr
> iptBytecodeAdapter.java:85)
> at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy)
> at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAc
> cessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(Reflection
> MetaMethod.java:67)
> at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaCla
> ssHelper.java:636)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> at groovy.lang.Closure.call(Closure.java:176)
> at groovy.lang.Closure.call(Closure.java:171)
> at groovy.lang.Closure.run(Closure.java:252)
> at java.lang.Thread.run(Thread.java:595)
>
>
>
> ---------------------------------------------------------------------
> 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-user] groovy+sql not-working example

Robert Fuller
In reply to this post by Željko Krstić
Sql.INTEGER is an sql out parameter of type integer.

I wonder if you have a version of Groovy containing this functionality?

Maybe try something like:
javap -classpath groovy.jar groovy.sql.Sql


Željko Krstić wrote:

>Hay all
>I find that sql+groovy "call stored oracle procedure" doesn't work
>(http://groovy.codehaus.org/Groovy+SQL). What is this ${Sql.INTEGER} ? It
>should be parameter used for returning value(s), but groovy doesn't recognize
>it as java.lang.Class field. I can find it in
>ojdbc14_g.jar\oracle\jdbc\OracleTypes ..
>Can someone pass me working example of Sql.call methode or help me understand
>why this doesnt't work?
>Thanks in advance
>
>Here's source:
>
>import java.sql.Connection
>import java.sql.DriverManager
>import javax.sql.DataSource
>import groovy.sql.Sql
>import oracle.jdbc.driver.OracleTypes
>
>driver = oracle.jdbc.driver.OracleDriver
>Connection conn =
>DriverManager.getConnection('jdbc:oracle:thin:scott/tiger@localhost:1521:XE');
>
>/*
> *
> * Here we call a procedural block with a closure.
> * ${Sql.INTEGER} and ${Sql.VARCHAR} are out parameters
> * which are passed to the closure.
> *
> */
>Sql sql = new Sql(conn);
>def a="foo";
>String foo = "x";
>println "${a}=${a}"
>undefinedVar = null
>println """
>--Simple demonstration of call with closure.
>--Closure is called once with all returned values.
>"""
>sql.call("begin ${Sql.INTEGER}:=20; ${Sql.VARCHAR}:='hello
>world';end;"){answer,string| println "number=[${answer}] string=[${string}]"
>   println "answer is a ${answer.class}";
>   println "string is a ${string.class}";
>   answer += 1;
>   println "now number=${answer}"
>   println """[${string.replaceAll("o","O")}]"""
>}
>
>
>Here's output:
>
>Exception thrown: groovy.lang.MissingFieldException: No such field: INTEGER for
>class: java.lang.Class
>
>groovy.lang.MissingFieldException: No such field: INTEGER for class:
>java.lang.Class
> at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:1074)
> at groovy.lang.MetaClassImpl.getStaticProperty(MetaClassImpl.java:1308)
> at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:707)
> at org.codehaus.groovy.runtime.Invoker.getProperty(Invoker.java:727)
> at
>org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:206)
> at
>org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:295)
> at Script17.run(Script17:26)
> at groovy.lang.GroovyShell.evaluate(GroovyShell.java:521)
> at groovy.lang.GroovyShell.evaluate(GroovyShell.java:462)
> at gjdk.groovy.lang.GroovyShell_GroovyReflector.invoke(Unknown Source)
> at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> at
>org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> at
>org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> at
>org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy:500)
> at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
> at
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
>org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> at
>org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> at
>org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> at
>org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy)
> at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
> at
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
>org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> at
>org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> at groovy.lang.Closure.call(Closure.java:176)
> at groovy.lang.Closure.call(Closure.java:171)
> at groovy.lang.Closure.run(Closure.java:252)
> at java.lang.Thread.run(Thread.java:595)
>
>
>
>---------------------------------------------------------------------
>To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>  
>


--
   Robert Fuller    Applepie Solutions Ltd   http://www.aplpi.com
email:[hidden email] mobile:+353.86.0507760 office:+353.91.751262
  Unit 30, Industry Support Centre, GMIT, Dublin Rd, Galway, Ireland.


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

    http://xircles.codehaus.org/manage_email