# Servoy 3.5.1 : Problem: Can't load records when date in args

**URL:** <https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263>\
**Category:** Classic Servoy\
**Created:** [October 18, 2007, 9:28am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263 "2007-10-18T09:28:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [October 18, 2007, 9:28am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/1 "2007-10-18T09:28:21Z")

</div>

Hi, I’m trying to work out if I’m doing something stupid or there is a bug:

I have a query

```auto
SELECT document_id FROM acc_documents WHERE date_trunc('day',document_date) = ? ORDER BY document_number DESC

```

And a date argument in the args array

```auto
[Tue Jan 09 2007 00:00:00 GMT-0000 (GMT)]

```

If I try

```auto
currentcontroller.loadRecords(query,args);

```

I get an error

```auto
Error loading primary key data, Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use.
com.servoy.j2db.dataprocessing.DataException: Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use.

```

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [October 18, 2007, 9:43am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/2 "2007-10-18T09:43:08Z")

</div>

What happens when you perform the query outside of Servoy?

---

<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:** [October 18, 2007, 9:45am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/3 "2007-10-18T09:45:00Z")

</div>

Can you show us, how you really create the arguments array for the query? Your quote looks like it is a string.

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [October 18, 2007, 9:52am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/4 "2007-10-18T09:52:41Z")

</div>

Hi, the argument is created using new Date(). The same query and args work when used in

databaseManager.getDataSetByQuery().

try this code (my table is called test2, with two fields, test2\_id and a\_date)

```auto
//CREATE SOME SAMPLE DATA
controller.loadAllRecords();
if(controller.getMaxRecordIndex() == 0) {
	for ( var i = 1 ; i < 10 ; i++ )
	{
		controller.newRecord();
		a_date = new Date();
		//MY TREE DOES NOT CONTAIN controller.saveData() !!!!
	}
}

//CODE WHICH FAILS
var query = "SELECT test2_id FROM test2 WHERE a_date = ? ORDER BY a_date";
var d = new Date();
var args = new Array();
args.push(d);
controller.loadRecords(query,args);

```

I have now created a case for this.

---

<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:** [October 18, 2007, 10:23am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/5 "2007-10-18T10:23:20Z")

</div>

Have you tried to use

```auto
controller.loadRecords(query, [d]); 

```

Maybe something goes wrong with push?

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [October 18, 2007, 3:28pm UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/6 "2007-10-18T15:28:52Z")

</div>

Hi Patrick,

tried your idea but I get the same error.

push is a fairly basic javascript function so I would have been surprised if it was the culprit.

The error-message I get is from java…

---

<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:** [October 18, 2007, 3:48pm UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/7 "2007-10-18T15:48:19Z")

</div>

I think I have seen your error before. Have you reported this one (with sample)? Dates are one of the main reasons for using a prepared statement, because you never know what the database expects…

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [October 18, 2007, 3:49pm UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/8 "2007-10-18T15:49:20Z")

</div>

Yep. I produced a sample solution which fails!

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [October 30, 2007, 9:11am UTC](https://forum.servoy.com/t/servoy-3-5-1-problem-cant-load-records-when-date-in-args/8263/9 "2007-10-30T09:11:57Z")

</div>

This issue has been solved in Servoy 3.5.3.

It was specific to Date objects in custom queries.

Rob
