Skip to content

Instantly share code, notes, and snippets.

@dalmat36
Created July 9, 2015 20:42
Show Gist options
  • Select an option

  • Save dalmat36/13bd24c9199a9b963ac9 to your computer and use it in GitHub Desktop.

Select an option

Save dalmat36/13bd24c9199a9b963ac9 to your computer and use it in GitHub Desktop.
Simple SQL Insert / Select with Groovy
import groovy.sql.Sql;
import java.sql.Connection
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
class GroovySQLTesting {
static main(args) {
def db = Sql.newInstance("jdbc:sqlserver://localhost;databaseName=MyDB;integratedSecurity=true", '', '', 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
db.execute 'exec proc_InsertNewPerson ?,?,?', ['matt', 30, 16803]
db.execute 'exec proc_InsertNewPerson ?,?,?', ['geoff', null, 16803]
db.execute 'exec proc_InsertNewPerson ?,?,?', ['max', null, 16803]
db.eachRow("select * from Person") {
println(it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment