1
我正在加載一個類並執行一些sql select語句,似乎需要導入import groovy.sql.Sql
。如何在加載課程時加載一些圖書館?如何在加載groovy類時導入文件?
我的代碼(如果我刪除SQL操作正常工作)
def fClass = new GroovyClassLoader().parseClass(new File('plugin/Pi.groovy'))
result=fClass.newInstance().buildTags(params, i9piparams, "userRoleCount")
pi.groovy
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*/
Driver="oracle.jdbc.driver.OracleDriver"
dbdriver="jdbc:oracle:thin"
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 ->
result.name=row.name
result.value=row.value
}
}
}
輸出
[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)
.
.
.
您好,我作出相應的chages和它給我'無效Url'這裏我的網址'jdbc:oracle:thin:@foner:1521:orcl'。另外關於Driver,我正在重構一箇舊代碼,所以錯過了它。 – abi1964 2012-04-23 12:30:19
你在系統類路徑上是否有oracle驅動程序? – 2012-04-23 12:32:36
@AbhishekSimon PS:我更新了我的[上一個答案](http://stackoverflow.com/a/10278678/6509)將'text()'調用應用於每個屬性調用 – 2012-04-23 12:33:41