• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stored procedures in JDBC?

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic