# How to read data using db connector into business variable?

**URL:** https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727
**Category:** Q&A
**Created:** [3 December 2015 17:05 UTC](https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727 "2015-12-03T17:05:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![juraj.tomaschek](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@juraj.tomaschek](https://community.ofelia.com/u/juraj.tomaschek)
#### Post date: [3 December 2015 17:05 UTC](https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727/1 "2015-12-03T17:05:55Z")

</div>

I would like to read data from an external MS SQL database using a connector and map the result into a business variable.

I have created a new Business Object called ‘MyObject’ with attributes ‘ID’ (integer) and ‘Status’ (String).  
Then I created a Pool Business variable called ‘loadedMyObjects’ of type ‘MyObject’ and I set the flag ‘IsMultiple’ as true so it should be a collection of ‘MyObject’ instances.

My workflow diagram consists of a Start event connected to a Service Task and finally an End event.

In the Service task I added a new Connector In to load data from MS SQL database table with columns being same as the attributes in the business object ‘MyObject’.  
The sql query to retrieve the data is:

`SELECT TOP 10 ID, Status FROM MyObject`

When I click the test button for the connector I get the data I want back. Here is a screenshot:  
 ![testresult](http://i63.tinypic.com/2nk3s5s.jpg)

Then I get to the ‘Output operations definition’ page and here I select to store the result in ‘loadedMyObjects’ pool variable and the operation to be ‘Takes value of’ and on the right side I choose to get the result as a expression in Script as seen in screenshot bellow:  
[mapping script]: [http://i68.tinypic.com/wqzvdf.png](http://i68.tinypic.com/wqzvdf.png)  
![mapping script][mapping script]

But here is where I got stuck and don’t know what should be in the script to get the data in the ‘resultset’ to my pool business variable ‘loadedMyObjects’.

I guess I will need to read the resultset and for each row create an ‘MyObject’ instance and set it’s properties but so far nothing worked for me and any help would be greatly appreciated.

Thanks

* * *

EDIT:

I found a solution and here is the groovy snippet for reference:

List myObjects = new ArrayList();  
while(resultset.next()) {  
def myObject = myObjectDAO.newInstance();  
myObject.ID = resultset.getInt(“ID”);  
myObject.Status = resultset.getString(“Status”);  
myObjects.add(myObject);  
}  
return myObjects;

---

<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: [3 December 2015 18:29 UTC](https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727/2 "2015-12-03T18:29:15Z")

</div>

You answered it…

Well found, regards

---

<div class="post-metadata">

### Author: ![FatmaGh](https://avatars.discourse-cdn.com/v4/letter/f/3e96dc/32.png) [@FatmaGh](https://community.ofelia.com/u/FatmaGh)
#### Post date: [17 September 2020 15:45 UTC](https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727/3 "2020-09-17T15:45:27Z")

</div>

do you know how to display values in a form?

---

<div class="post-metadata">

### Author: ![delinare.its](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@delinare.its](https://community.ofelia.com/u/delinare.its)
#### Post date: [28 December 2016 02:35 UTC](https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727/4 "2016-12-28T02:35:07Z")

</div>

Hello, I want to know what type did you use in LoadedMyObject object?  
and I’ve put the script on groovy and when I clicked ‘evaluate’, the screen show me that it’s need to be define value for resultset and myObjectDAO. What should I do?

Thanks before,

---

<div class="post-metadata">

### Author: ![aduthoy](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@aduthoy](https://community.ofelia.com/u/aduthoy)
#### Post date: [4 December 2015 03:00 UTC](https://community.ofelia.com/t/how-to-read-data-using-db-connector-into-business-variable/6727/5 "2015-12-04T03:00:36Z")

</div>

Hello Edit.

I have the same problem as you, As i can see from Sean you have the solution, but I don’t understand the way to send the information to your BDM. Could you send me your example please?. thanks in advance.
