The CallableStatement Interface

September 28th, 2006 Admin Posted in JDBC (java database connectivity) No Comments »

The callable statement interface is used to call the stored procudure in the databse. Please remember that, it is only a mechanism to execute the stored procudure but not an encapsulation of stored procudure.

A callable statement interface indicate a call to singlel stored procedure. The next thing to do is passing some parameters  to the stored procedure. In case of java, java variables and constents are not passed as arguements. The actual procedure of passing aparameters is described in the next sub sections.

Since the stored procedures are database dependent, their calling methods are also database dependent. and each database has different mechanism to call stored procedures and pass parameters. While using JDBC in order to connect most database, a standard format is maintained which is to be converted to the native format by the JDBC  driver.

The format is shown below

{call

(?,?,?)}

where each “?” symbol represents an arguements to the procedure. Remember each parameter could be an IN,OUT and INOUT parameter.

Now, an object of callable statement to encapsulate a  single call should be created, this can be done by calling the prepare call () method of connection interface. To this method CALL statement is passed as the arguements. An Example of this is shown below

Callablestatement CStmt = con.prepare(”{CALL

(?,?,?)}”);

The callable statement interface is inherited from the prepared statement interface and hence it will have all the functions of prepared statement interface.

AddThis Social Bookmark Button

IN,OUT and INOUT Parameters

September 28th, 2006 Admin Posted in JDBC (java database connectivity) No Comments »

IN parameters are mainly to send information to the stored procedure.

For Example you might have written a stored procedure to increase a salary of an employee by 10%. then you need to pass the eno as a parameter to the procedure since it means to know whose salary ids to be changed. In parameters can be specified only in the right hand side of expressions and not on the left hand side since it will be treated as a constant with in the procedure.

OUT parameters are mainly used to retrieve the information from the database using a stored procedure.

For example you may want to find out a maximum, minimum and average salary of all employee. In such case you need to have stored procedure which will have three out parameters. Like in parameter,out parameter cant be specified in the right hand side of expression. However, the calling program should send the empty variable, which will hold the result of the expression.

INOUT parameters can be used send information as well as to receive it. INOUT parameter can be specified on the both sides of the expression. This is because, they carry the information into the procedure, as well to the calling program.

AddThis Social Bookmark Button

How to create stored procedures

September 28th, 2006 Admin Posted in JDBC (java database connectivity) No Comments »

The stored procedures are database depentdent, there are different ways to create stored procedures for different databases. However they follow some common guide-lines in accessing parameters and returning results.

In general all the stored procedures will have a name associated with ,and a list of parameters they accept, along with their datatypes after this parameter list, you will find a declarations section, where all the local variables are declared.Then starts the actual code for the stored procedures. Optionally you will find an exceptions section,to handle any errors in the program.

Syntax:

Create procedure

(param [param type],…….) as

// local declarations go here

Begin

// actual procedure code

End

Creating Stored Procedures

A procedures to create a stored procedure in ORACLE is given in this section

  • open SQL plus and log into the database.
  • Start windows notepad and write down the stored procedure.
  • Execute the statement in SQL plus by giving the file name in which the stored is present.
AddThis Social Bookmark Button