The exception is coming from Derby, so this is most likely your query - I don't know what specifically about the query is causing it, but can say the query you are using could probably be constructed...