For a secure, consistent and manageable multi-tier Client/Server systems, the data access should be allow the use of stores procedures. Stored procedures centralize the business logic in terms of manageability and also in terms of running the query. Java applets running on clients with limited resources cannot be expected to run huge queries. But the results are important to those clients. JDBC allows the use of stored procedures by the CallableStatement class and with the eascape clause string.
A CallableStatement object is created by the prepareCall() method in the Connection object. The prepareCall() method takes a sting as the parameter. This string, called as escape clause, is of the form:
{[?=] call <stored procedure name> [<parameters>, <parameters>,..]}
The CallableStatement class supports parameters. These parameters are of the OUT kind from a stored procedures or the IN kind to pass values into a stored procedure. The parameters marker (question mark ?) must be used for the return value (if any) and any output arguments because the parameter marker is bound to a program variable in the stored procedure. Input arguments can be either literals or parameters. For a dynamic parameterized statement, the escape clause string takes the from:
{[?=] call <strored procedure name> [<?>,<?>,…]}
The OUT parameters should be registerd using the registerOutparameter() method before the call to the executeQuery(), executeUpdate() or execute() methods.
After the stored procedure is executed, the DBMS returns the result value to the JDBC driver. This return value is accessed by the Java program using the methods.
As you can see, JDBC has minimized the complexities of getting results from a stored procedure.



No comments:
Post a Comment