GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  JDBC
Go To First  |  Previous Question  |  Next Question 
 JDBC  |  Question 26 of 135    Print  
How to call a Stored Procedure from JDBC?
The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure;
E.g.
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();



  
Total Answers and Comments: 2 Last Update: September 23, 2005   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 16, 2005 21:11:32   #1  
Jaime        

RE: How to call a Stored Procedure from JDBC?
This document demonstrates how to return a JDBC ResultSet as REF CURSOR from a Java Stored Procedure. JDBC ResultSet is a table of data representing a database, which is usually generated by executing a statement that queries the database. REF CURSOR is the corresponding type in PL/SQL. The call specification of the Java Stored Procedure maps ResultSet to REF CURSOR. Prior to Oracle9i, it was not possible to return a ResultSet directly from a Java Stored Procedure because there was no mapping defined of the form ResultSet->REF CURSOR. Oracle9i adds this mapping to permit returning ResultSet from a function or as an OUT parameter to some procedure. The reverse mapping (REF CURSOR->ResultSet) is still not supported, so IN and IN OUT parameters are still not supported with current version of the database. 
 
In this How to, we have 2 Java Stored Procedures. The Java Stored procedure getEmployees() fetches all the columns of EMP table in the SCOTT schema into a ResultSet and return it. The Java Stored Procedure getDepartments(ResultSet[] rout) takes a ResultSet object as a OUT parameter and fetches all the columns of DEPT table into this ResultSetobject.  
 
Click here to Read Complete Tutorial

 
Is this answer useful? Yes | No
September 23, 2005 17:28:41   #2  
guptach Member Since: September 2005   Contribution: 10    

How to call a Stored Procedure from JDBC?

Stored Procedures can be called in java by using the prepareCall() method which returns a CallableStatement object.

CallableStatement cs = con.prepareCall("{call Procedure_name}");

ResultSet rs = cs.executeQuery();


 
Is this answer useful? Yes | No

 Related Questions

Answered by Jey on 2005-05-10 05:53:50: 1.Statement which is used to run simple sql statements like select and update 2. PrepareStatment is used to run Pre compiled sql.  3. CallableStatement 
Latest Answer : Load the driver class using class.forName(driverclass) and class.forName() loads the driver class and passes the control to DriverManager class ...

Latest Answer : Stored procedure contains set of sQL Statements thar are executed in the database by the sql stament processor.code:DECLARE NUM1 NUMBER:=10; NUM2 NUMBER:=20;BEGIN    DBMS_OUTPUT.PUT_LINE('sum:'||To_Char(NUM1+NUM2,'999.99'));END; ...

Answered by Jey on 2005-05-10 06:01:10: Here are the steps.  Using DriverManager: 1. Load the driver class using class.forName(driverclass) and class.forName() loads the driver class and 
Latest Answer : First we register the connection and after that we connect the database, in that we give to which database is connecting giving that  ipaddress ,port number,username and password . ...

Latest Answer : Also JDBC2.0 provides extended support for transactions that includes batch updates and savepoints ...

JDBC is a layer of abstraction that allows users to choose between databases. It allows you to change to a different database engine and to write to a single API. JDBC allows you to write database applications 
Latest Answer : JDBC is a core API of Java 1.1 and later which provides a standard set of interfaces to SQL-compliant databases. ...

One implementation interface for database manufacturers, the other implementation interface for application and applet writers. 
Latest Answer : JDBC has four major components:1.The JDBC API2.The JDBC Driver Manager3.The JDBC Test Suite4.The JDBC-ODBC Bridge      The first two components of JDBC,the JDBC API and the JDBC Driver Managermanages to connect to the database ...

The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendors driver must provide implementations of the java.sql.Connection,Statement,PreparedStatement, 
Latest Answer : As has been mentioned above, the implementations are provided by the database vendors like for example, the classes12.jar of oracle which has the implementations. ...

Create an instance of a JDBC driver or load JDBC drivers through jdbc.driversRegister a driverSpecify a databaseOpen a database connectionSubmit a queryReceive results 
Latest Answer : import java.sql.*;class Type1 { public static void main(String[] args)throws Exception {  Connection c=null;  try  {    Driver d=new Driver("sun.jdbc.odbc.JdbcOdbc");     //or  ...

There are 8 packages: java.sql.Driver, Connection,Statement, PreparedStatement, CallableStatement, ResultSet, ResultSetMetaData, DatabaseMetaData. 
Latest Answer : Packages arejava.sql and javax.sql only..Those mentioned in the previous lists are the classes & interfaces in those packages. ...

A URL string -->getConnection-->DriverManager-->Driver-->Connection-->Statement-->executeQuery-->ResultSet. 
Latest Answer : 1). Register the Driver 2) load the Driver 3)get the connection 4) create the statement 5) Execute the query 6) fetch the results with ResultSet ...


 Sponsored Links

 
Related Articles

What are the differences between stored procedures and triggers?

Stored procedures are compiled collection of programs or SQL statements that live in the database. A stored procedure can access and modify data present in many tables. Also a stored procedure is not associated with any particular database object. But triggers are event-driven special procedures whi
 

How does the function call within function get evaluated?

Whenever we have more than one function which is called for a finite number of times then such a function gets evaluated from inside out. Let us understand this concept with an example. For instance consider a function sample called within it 4 times as given in program below: main() { int a=50;
 

How to call C header that is not provided generally by system in C++?

Headers can be called by using extern C Syntax of extern C is: extern "C" <function declaration> for example to call C functions from C++ we can write extern "C" { <function declaration> <function declaration> ...
 

What is difference between call by value and call by reference in function?

The arguments passed to function can be of two types 1. Values passed 2. Address passed The first type refers to call by value and the second type refers to call by reference. For instance consider program1 main() { int x=50, y=70; interchange(x,y); printf(“x=%d y=%d”,x,
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

XML Remote Calling Procedure

XML Remote Calling Procedure XML RPC or the XML Remote Calling Procedure is a set of compilations and implementations which allow certain programs to run on complex platforms or operating systems and allows them to make Remote Procedure calls on the Internet The Remote Procedure Calling Protocol use
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

Procedure for getting Scholarships

Procedure for getting Scholarships If you have done a bit of research you are probably well aware of the fact that there is a great deal of money available for scholarships Having said that it is sad to see that so many students graduate from college with lots of students loans when they could have
 

How Data Is Stored Within a Data Warehouse

How Data Is Stored Within a Data Warehouse The data that is stored in the data warehouse is just as important as the data warehouse itself Having a fundamental understanding of how this data is stored can be useful in the successful implementation and utilization of a data warehouse One term that yo
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape