Executing multiple sql query from groovy script

1
0
-1

Hello,

I'm trying to execute mutiples sql queries from groovy, but only the first query is executing, the rest never gives me any result, here is my script

import groovy.sql.Sql;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.Logger;

import org.bonitasoft.engine.bpm.process.ProcessInstance;

import com.mysql.jdbc.Driver;

Logger logger=Logger.getLogger("org.bonitasoft")
Sql sql = BonitaSql.newInstance("jdbc:mysql://localhost:3306/projetbonita", "root", "", new Driver());

Statement stm = sql.getConnection().createStatement();

for(String tech : technologie.split(",")){

        ResultSet rs = stm.executeQuery("select * from technology where name like '"+ tech +"'");
        int id = 0;
        if(rs.next()){
                id = rs.getInt(1);
        }
       
        logger.severe(id.toString());
}

only the first "id" is shown, the rest is always "0". I want to grab all the ids then perform a certain operation. What am i doing wrong?

1 answer

1
0
-1

I would do this

String[] tempTech = technologie.split(",");
for(String tech : tempTech){
...
}

Is it possible that in your version of the for it is redoing the split every time and, as you see, only get the first id...

regards

Notifications