java - How to get DataSource connection from a Groovy Class with this groovy code? -
i used have java class in grails app, needed connection datasource.groovy
passed groovy class, , made getting context application. how can connect that datasource code?:
def datasource = ctx.getbean('datasource_executer') // auto injected , referenced datasource connection conn = null; statement stmt = null; class.forname('driver'); conn = drivermanager.getconnection(datasource);// here it's trouble
i need because need metadata of result query this:
stmt = conn.createstatement(); def rs = stmt.executequery('query'); def rsmd = rs.getmetadata(); num = rsmd.getcolumncount();
and control while:
while(rs.next()){..........}
i use groovy.sql
package this.
import groovy.sql.groovyrowresult import groovy.sql.sql def datasource = ctx.getbean('datasource_executer') def connection = new sql(datasource) def results = connection.rows('select ...') results.each { r -> println r['columnname'] ... }
you can access resultsetmetadata
well. blog post has example of how so.
Comments
Post a Comment