Monday, April 23, 2012

How to import files while loading a groovy class?

I am loading a class and doing some sql select statements, it seems that import groovy.sql.Sql needs to be imported. How can I load some library while loading a class?

My code (works fine if I remove Sql operations)

def fClass = new GroovyClassLoader().parseClass( new File( 'plugin/Pi.groovy' ) )
result=fClass.newInstance().buildTags( params, i9piparams, "userRoleCount")


public class Pi{
def result

private def getDbUrl(dbdriver,dbhost,dbport,dbname)
return "$dbdriver:@$dbhost:$dbport:$dbname"

public def buildTags(Map<String,String> params,Map<String,String> i9piparams,def i9piType)

println params
println i9piparams

/*some Sql operation*/
def url=getDbUrl(dbdriver,params.tns,i9piparams.dbport,i9piparams.dbname)

def sql = Sql.newInstance(url,params.u,params.x,Driver)

sql.eachRow("select name, value from v\$parameter where name = 'open_cursors'"){ row ->



[pd:admin, u:zx5531d, tns:foner, dh:abds, dn:D35531, dp:11531, un:admin, x:cx15531]
[:, dbname:orcl, dbport:1521, dbtype:oracle]
Exception in thread "main" groovy.lang.GroovyRuntimeException: Could not find matching constructor for: groovy.sql.Sql(org.codehaus.groovy.runtime.GStringImpl, groovy.util.slurpersupport.Attributes, java.lang.String, java.lang.String)

No comments:

Post a Comment