Let's step back a bit and find out what you're doing.
Start with your query:
What does your SQL query look like, and what is it trying to achieve?Are you really trying to fetch 165 million rows into your Java application?If so, is it really necessary to do this, or could you fetch the information you require some other way e.g. via SQL aggregate functions?If you don't really need to fetch all this data, stop now and re-write your query so you only fetch what you need.If you really do need to fetch all this data, have you tried running the same query directly in your SQL*Plus (or SQL Developer) client?If so, what happens e.g. how long does it take to run?If you haven't run it from a proper SQL client, do so and see what happens.Have you asked your DBA to check the database logs to see what might have happened?
If your query is working OK and it is what you really need to do, then it's time to look at how it's working with JDBC. You'll need to check out the
Oracle JDBC developer's guide for details on how to use Oracle JDBC drivers, or ask extra questions here. I don't use Java these days, and I don't have an Oracle RDBMS or app server available, so right now I can only suggest a few places to look for problems.
Make sure your code is not simply swallowing any exceptions.Are you using an application server e.g. WebLogic? If so, you'll need to check the logs and connection settings etc in your app server.Did your application or database logs show any errors or strange behaviour when you tried this query?As Roel says, it could be a connection timeout because this query takes so long to run.It could be a memory problem if your app is trying to read 5GB of data - this could be happening in your app server (if any), on your client or inside the database. Check the logs.Are you running your app server with a fixed amount of RAM per session?
There are probably lots of other possibilities, but right now it's hard to know what to suggest because we don't really know anything about what you're actually doing.