Question

When a Java call gets made to Oracle or a similar RDBMS, how does Java know that the Oracle action has completed?

For instance, "create table as (select * from table1)".

If we execute that single line SQL statement in Oracle via Java, how does Java know that the line of code has completed, and moves on to the next Java instruction? My guess is there is some secretive JDBC going on but not sure what it is.

Can someone explain?

I hope that the time required to execute that line of code in Java could be adjusted. If you don't want a ResultSet object back, and just want some sort of confirmation instead, then you could fine tune something.

Was it helpful?

Solution

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.

OTHER TIPS

This is taken care of by the JDBC driver you are using. It knows how to "talk" to the database. It transfers the query to the database and returns the result back to client. The database will always respond with a result (A ResultSet, update count, etc), otherwise an exception would be raised and you would know usually through an SQLException or SQLTimeoutException. The API is well documented in case you want to dig deeper. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top