example: I have a CSV file like this

and I want it to be saved in the database .. with loading CSV files.
this is my coding for loading csv file
<input type="file" name="filecsv"/>
<input type="button" class="upload" value="Upload
onclick='location.href ="${createLink(url: [action: 'upload'])}"'/>
I got confused in groovy .. I tried like this code but didn't succeed.
def upload = {
println params.filecsv
new File('filecsv').splitEachLine(',') {fields ->
def city = new City(
city: fields[0].trim(),
description: fields[1].trim()
)
if (city.hasErrors() || city.save(flush: true) == null) {
log.error("Could not import domainObject ${city.errors}")
}
log.debug("Importing domainObject ${city.toString()}")
}
Parsing CSV and exporting to the Mysql database in Grails
how to get data from csv file and save it in mysql database?
source
share