aspose file tools
The moose likes JDBC and the fly likes Stored procedures in JDBC? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Stored procedures in JDBC?" Watch "Stored procedures in JDBC?" New topic
Author

Stored procedures in JDBC?

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 375
Hi, I have a simple app calling Oracle using an embedded SQL call.
How do I convert it to using a stored procedure?

package db;

import java.sql.*;
import oracle.jdbc.OracleDatabaseMetaData;

public class DBTestOracle {

public static void main(String[] args) {

final String dbURI = "jdbc racle:thin:@AVL-AVALON:1521:JINX";
final String oracleDvr = "oracle.jdbc.driver.OracleDriver";
Connection conn = null;
try {

Driver oDvr = new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver (oDvr);
conn = DriverManager.getConnection(dbURI,"scott","tiger");
conn.setAutoCommit(false);

Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from scott.emp");
while (rset.next())System.out.println (rset.getString(1) +
rset.getString(2)+rset.getString(3)+rset.getString(4)+rset.getString(5)
+rset.getString(6)+rset.getString(7)+rset.getString(8));

conn.commit();
rset.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
[ January 30, 2005: Message edited by: M Burke ]
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1112

M,
If I understand you correctly, you want to create a stored procedure that returns the results of a simple query. If this is true, then I suggest searching the OTN and Ask Tom Web sites for the term "ref cursor".

If you require information on how to create stored procedures (in Oracle) and how to invoke stored procedures from JDBC, I suggest perusing the Oracle documentation, which is available from the Tahiti Web site. In particular, look at the "PL/SQL User's Guide and Reference" as well as the "JDBC Developer's Guide and Reference".

Good Luck,
Avi.
[ January 30, 2005: Message edited by: Avi Abrami ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Stored procedures in JDBC?
 
Similar Threads
Huge result sets
how i pass recordset value to string variable
jdbc error
how pass record value in string variable and how return record value to applet
Reg: Writing Oracle JavaStored Procedures