I have a Groovy script that is using the groovy.sql.Sql
class to communicate with the DB, but some legacy Java code is expecting to receive a java.sql.ResultSet
. Is there any way to execute a SELECT
query using groovy.sql.Sql
and directly return the java.sql.ResultSet
?
Not really. One of the main reasons to use Groovy's Sql
is to automatically handle resources (which is why there are methods using closures to interact with the ResultSet
, but none that return it -- to ensure they get closed). I'd strongly recommend revisiting why you are passing around references to ResultSet
(which could be holding onto server resources) rather than using a POJO/POGO representing those results.
However, if you insist on using ResultSet
, and you only need few convenience methods, I guess one option would be to copy those methods into your codebase. As you can see from the source , Sql
is a pretty thin wrapper over plain old JDBC. But for what it sounds like you're doing, I question how much value it adds.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.