Pages

Subscribe:

Ads 468x60px

Tuesday, November 1, 2011

JDBC Statements

         A Java application program first builds the SQL statement in a string buffer and passes this to the underlying DBMS through some API calls. An SQL statement needs to be verified syntactically, optimized, and converted to an executable form before execution. In the Call Level Interface (CLI) Application Program Interface (API) model, the application program through the driver passes the SQL statement to the underlying DBMS, which prepares and executes the SQL statement.
After the DBMS recieves the SQL string buffer, it parses the statement and does a syntax check run. If the statement is not syntactically correct, the system returns an error condition to the driver, which generates an SQLException. If the statement is syntactically correct, depending  on the DBMS, many query plans are usually generated that are run through an optinizer. Then the optimum plan is translated into a binary execution plan. After the execution plan is prepared, the DBMS usually returns a handler or identifier to this optimized binary version of the SQL statement to the application program.

      The three JDBC statement types (Statement, PreparedStatement and CallableStatement) differ in the timing of the SQL statement preparation and thie statement execution. In the case of the simple Statement object, the SQL ie prepared and executed in one step at least from the application program point of view, (Internally, the driver might get the identifier, command the DBMS to execute the query, and then discard the handle).
In the case ofa PreparedStatement object , the driver stores the execution plan handle for later use. In the case of the CallableStatement object, the SQL statement is actually making a call to a stored procedure that is usually already optimized.

No comments:

Post a Comment