• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stored procedures in JDBC?

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic