Skip to content

Instantly share code, notes, and snippets.

@cooniur
Last active December 19, 2016 22:01
Show Gist options
  • Save cooniur/71d2e625f69bd76167a97f2c64e6040c to your computer and use it in GitHub Desktop.
Save cooniur/71d2e625f69bd76167a97f2c64e6040c to your computer and use it in GitHub Desktop.
Groovy script using MySQL
@GrabConfig(systemClassLoader=true )
@Grab("mysql:mysql-connector-java:5.1.40")
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/test", "root", "root", "com.mysql.jdbc.Driver")
def users = sql.rows("SELECT * FROM users")
println "Users: ${users.size()}"

Output is:

~$ groovy conn.groovy
Users: 13

~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment