一
存儲過程為
CREATE OR REPLACE PROCEDURE TESTA(PARA
BEGIN
INSERT INTO HYQ
END TESTA
然後呢
package com
import java
import java
public class TestProcedureOne {
public TestProcedureOne() {
}
public static void main(String[] args ){
String driver =
String strUrl =
Statement stmt = null
ResultSet rs = null
Connection conn = null
CallableStatement cstmt = null
try {
Class
conn = DriverManager
CallableStatement proc = null
proc = conn
proc
proc
proc
}
catch (SQLException ex
ex
}
catch (Exception ex
ex
}
finally{
try {
if(rs != null){
rs
if(stmt!=null){
stmt
}
if(conn!=null){
conn
}
}
}
catch (SQLException ex
}
}
}
}
當然了
二
存儲過程為
CREATE OR REPLACE PROCEDURE TESTB(PARA
BEGIN
SELECT INTO PARA
END TESTB
在java裡調用時就用下面的代碼
package com
public class TestProcedureTWO {
public TestProcedureTWO() {
}
public static void main(String[] args ){
String driver =
String strUrl =
Statement stmt = null
ResultSet rs = null
Connection conn = null
try {
Class
conn = DriverManager
CallableStatement proc = null
proc = conn
proc
proc
proc
String testPrint = proc
System
}
catch (SQLException ex
ex
}
catch (Exception ex
ex
}
finally{
try {
if(rs != null){
rs
if(stmt!=null){
stmt
}
if(conn!=null){
conn
}
}
}
catch (SQLException ex
}
}
}
}
}
注意
三
由於oracle存儲過程沒有返回值
CREATE OR REPLACE PACKAGE TESTPACKAGE AS
TYPE Test_CURSOR IS REF CURSOR
end TESTPACKAGE
CREATE OR REPLACE PROCEDURE TESTC(p_CURSOR out TESTPACKAGE
BEGIN
OPEN p_CURSOR FOR SELECT * FROM HYQ
END TESTC
可以看到
在java裡調用時就用下面的代碼
package com
import java
import java
import java
import java
import java
import oracle
public class TestProcedureTHREE {
public TestProcedureTHREE() {
}
public static void main(String[] args ){
String driver =
String strUrl =
Statement stmt = null
ResultSet rs = null
Connection conn = null
try {
Class
conn = DriverManager
CallableStatement proc = null
proc = conn
proc
proc
rs = (ResultSet)proc
while(rs
{
System
}
}
catch (SQLException ex
ex
}
catch (Exception ex
ex
}
finally{
try {
if(rs != null){
rs
if(stmt!=null){
stmt
}
if(conn!=null){
conn
}
}
}
catch (SQLException ex
}
}
}
}
CallableStatement cs = conn
CallableStatement cs= conn
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26452.html