Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb",
  2. "user", "pswd", "com.mysql.jdbc.Driver")
  3. def people = sql.dataSet("PERSON")
  4. new File("users.csv").splitEachLine(",") {fields ->
  5. people.add(
  6. first_name: fields[0],
  7. last_name: fields[1],
  8. email: fields[2]
  9. )
  10. }
  11.  
  12. @Grab('com.xlson.groovycsv:groovycsv:0.2')
  13. import com.xlson.groovycsv.CsvParser
  14.  
  15. def csv = '''Name,Lastname
  16. Mark,Andersson
  17. Pete,Hansen'''
  18.  
  19. def data = new CsvParser().parse(csv)
  20. for(line in data) {
  21. println "$line.Name $line.Lastname"
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement