I guess someone with more knowledge about Derby's internals may be able to tell you why your specific query requires a larger stack size.
I think that the query was noted to use an IN clause, so he may be encountering either http://issues.apache.org/jira/browse/DERBY-47 or http://issues.apache.org/jira/browse/DERBY-713.
Robert, can you tell us more about the particular query that is giving you trouble? thanks, bryan