Last active
December 20, 2015 04:39
-
-
Save linkerlin/6071999 to your computer and use it in GitHub Desktop.
Groovy and load a jar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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