Skip to content

Instantly share code, notes, and snippets.

@linkerlin
Last active December 20, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linkerlin/6071999 to your computer and use it in GitHub Desktop.
Save linkerlin/6071999 to your computer and use it in GitHub Desktop.
Groovy and load a jar
this.class.classLoader.rootLoader.addURL(new URL("file:////Users/linkerlin/.m2/repository/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar"))
import groovy.sql.Sql
sql = Sql.newInstance("jdbc:mysql://localhost:3306/test", "root", "", "com.mysql.jdbc.Driver")
sql.eachRow("SELECT id, username FROM users")
{
println "The employee's name is ${it.username}"
}
// Or using grape
@GrabConfig(systemClassLoader=true) // this is very important...
@Grapes(
@Grab(group='mysql', module='mysql-connector-java', version='5.1.21')
)
import groovy.sql.Sql
sql = Sql.newInstance("jdbc:mysql://localhost:3306/test", "root", "", "com.mysql.jdbc.Driver")
sql.eachRow("SELECT id, username FROM users")
{
println "The employee's name is ${it.username}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment