Skip to content

Instantly share code, notes, and snippets.

@dalmat36
Created July 22, 2015 19:49
Show Gist options
  • Save dalmat36/7b0306b3287a61368448 to your computer and use it in GitHub Desktop.
Save dalmat36/7b0306b3287a61368448 to your computer and use it in GitHub Desktop.
Query result from Database using Groovy
import java.sql.ResultSet
import groovy.sql.Sql;
class GroovySQLQueryPerson {
static main(args) {
def db = Sql.newInstance("jdbc:sqlserver://localhost;databaseName=MyDB;integratedSecurity=true", '', '', 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
db.query('SELECT id FROM Person WHERE name = ?', ["Sam"]){ ResultSet rs ->
while(rs.next()) println rs.getInt("id")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment