# Executing multiple sql query from groovy script

**URL:** <https://community.ofelia.com/t/executing-multiple-sql-query-from-groovy-script/5916>\
**Category:** Q&A\
**Created:** [8 May 2015 10:09 UTC](https://community.ofelia.com/t/executing-multiple-sql-query-from-groovy-script/5916 "2015-05-08T10:09:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wannes.fedi](https://avatars.discourse-cdn.com/v4/letter/w/b9e5f3/32.png) [@wannes.fedi](https://community.ofelia.com/u/wannes.fedi)\
**Post date:** [8 May 2015 10:09 UTC](https://community.ofelia.com/t/executing-multiple-sql-query-from-groovy-script/5916/1 "2015-05-08T10:09:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [8 May 2015 10:43 UTC](https://community.ofelia.com/t/executing-multiple-sql-query-from-groovy-script/5916/2 "2015-05-08T10:43:36Z")

</div>

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
