The dataset is not at all big...
As it is not a production DB, it has total 5 tables with not more than 20 records each.
And the exception I said (java.sql.SQLException: Out of memory) is also not coming consistantly.
Initially I too thought that the query might require more memory... but it is very simple select query. This 'Out of memory' seems misleading to me.
Please respond,