The same way that any other network request gets a response.
When you send a query to the database, the JDBC driver sends a bunch of packets over the network and awaits a response. When the database has the response (in the case of Oracle, when the first N rows are available), the driver receives a bunch of packets from the database that constitute the response. The JDBC driver parses the information in those packets and notifies your application according to the JDBC API.
This is exactly the same process that happens when there is any sort of client/ server network request. How does your web browser know when the HTTP request it has sent to the HTTP server has been processed? It knows when the HTTP server's response starts to arrive. The HTTP server then parses that response and then presents the information to you according to things like HTML standards.