I am trying to write an GroovySQL script that will have three different Arraylist variable. A1[1,2,3],A2[4,5,6],A3[7,8,9].
I want to update the table such that three rows of the three columns of the table are updates as
Data should be (in row wise)
R1: 1,4,7
R2: 2,5,8
R3: 3,6,9
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/words", "Test",
"test", "com.mysql.jdbc.Driver")
def nid = 1
def newupdate = "hello world"
sql.executeUpdate("update word set spelling = ? where word_id = ?", [ newupdate, nid])
I managed know how to update one row. I will be thankful if anyone can give any hints or ideas.
All you need to do is create a 2d array and transpose it, then execute the update query by loop thru it.
Here is the script:
You may see how the query is build in below:
Credits to tim_yates for transpose matrix