Skip to content

Instantly share code, notes, and snippets.

@peysal
Created March 26, 2014 09:23
Show Gist options
  • Save peysal/9779537 to your computer and use it in GitHub Desktop.
Save peysal/9779537 to your computer and use it in GitHub Desktop.
Basic sql query to db using groovy
import groovy.sql.Sql
String db_server = "bun"
String db_database = "bun"
String db_port = "1433"
String db_user = "bun"
String db_password = "bun"
String connectionUrl = "jdbc:sqlserver://" + db_server + ":" + db_port +
";database=" + db_database +
";user=" + db_user +
";password=" + db_password;
sql = Sql.newInstance( connectionUrl, "com.microsoft.sqlserver.jdbc.SQLServerDriver")
sql.eachRow( 'select top 1 * from Account' ) { println "$it" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment