# getDataSetByQuery and integer parameters

**URL:** <https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540>\
**Category:** Classic Servoy\
**Created:** [December 19, 2007, 10:15am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540 "2007-12-19T10:15:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [December 19, 2007, 10:15am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540/1 "2007-12-19T10:15:19Z")

</div>

Since a while (I think since 3.5.2) I have the following problem:

See the coding:

```auto
var _table_id = parseInt(arguments [0]);

application.output(typeof(_table_id));

var _query = 'SELECT database_table_field_id, fieldname FROM database_table_field WHERE database_table_id = ?'
var _ds = databaseManager.getDataSetByQuery('servername', _query, new Array(_table_id), -1)

```

The method is being called. When I check the debugger I see value 297 in my variable ‘\_table\_id’; The parseInt() was added to test, but without this parseInt() is goes wrong as well.

The typeof() function returns ‘number’

But the line with getDataSetByQuery() gives the following error:

> JSDataSet:exception:com.servoy.j2db.dataprocessing.DataException: Unable to convert between java.lang.Object and JAVA\_OBJECT.

And I really don’t know why this error is triggered. This kind of construction I use very often and only on certain places I get this error. Specially when using an integer parameter.

When I change my query to:

```auto
var _query = 'SELECT database_table_field_id, fieldname FROM database_table_field WHERE database_table_id = ' + _table_id
var _ds = databaseManager.getDataSetByQuery('servername', _query, null, -1)

```

then it works all correct, so it has something to do with using (integer) parameters.

Anyone has the same problem?

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [December 19, 2007, 10:39am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540/2 "2007-12-19T10:39:24Z")

</div>

The problem is that

```auto
new Array(5)

```

constructs an **empty** array of **length 5**. If you have

```auto
new Array(5, 2, 3)

```

it is no problem. It is safer to do this

```auto
databaseManager.getDataSetByQuery('servername', _query, new [_table_id], -1)

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [December 19, 2007, 10:51am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540/3 "2007-12-19T10:51:29Z")

</div>

Hi Patrick,

Thanks for your reply, I understand what you want to say, but the solution you gave doesn’t work.

> databaseManager.getDataSetByQuery(‘servername’, \_query, new [\_table\_id], -1)

I’m getting error about “Invalid function”.

But I rewrote my coding like this

```auto
var _args = new Array()
_args[0] = _table_id

var _query = 'SELECT database_table_field_id, fieldname FROM database_table_field WHERE database_table_id = ?'
var _ds = databaseManager.getDataSetByQuery('servername', _query, _args, -1)

```

and now it works also

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [December 19, 2007, 10:59am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540/4 "2007-12-19T10:59:46Z")

</div>

sorry, remove the “new” and my approach also works ![:wink:]( "Wink")

---

<div class="post-metadata">

**Author:** ![pbs](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@pbs](https://forum.servoy.com/u/pbs)\
**Post date:** [December 19, 2007, 11:01am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540/5 "2007-12-19T11:01:34Z")

</div>

I think in the previous case  
you were creating an array of length \_table\_id using new Array(\_table\_id)

so array size was equal to \_table\_id . but having null values

May be this was the problem

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [December 19, 2007, 11:06am UTC](https://forum.servoy.com/t/getdatasetbyquery-and-integer-parameters/8540/6 "2007-12-19T11:06:17Z")

</div>

> sorry, remove the “new” and my approach also works

Thanks, you are right.  
That avoids to make an extra variable for the argument like I did in my second solution
