創建存儲過程的腳本
使用sqlserver
create procedure showAll
as
select * from jobs
create procedure obtainJob_desc
@outputParam varchar(
@id int
as
select @outputParam = job_desc from jobs where job_id = @id
create procedure obtainReturn
as
declare @ret int
select @ret = count(*) from jobs
return @ret
declare @ret int
exec @ret = obtainReturn
print @ret
用來獲得連接的函數
public Connection getConnection()
Connection con = null;
try
Class
con = DriverManager
} catch (Exception e)
e
}
return con ;
}
public void getResultSet()
//獲得連接
Connection con = this
try
//showAll為存儲過程名
java
ResultSet rs = cstm
while(rs
//這裡寫邏輯代碼
System
}
rs
con
} catch (SQLException e)
// TODO Auto
e
}
}
public void getOutParameter(int inParam)
String outParam;
Connection con = this
try
CallableStatement cstm = con
cstm
cstm
cstm
//得到輸出參數
String outParma = cstm
System
cstm
con
} catch (SQLException e)
// TODO Auto
e
}
}
public void getReturn()
int ret;
Connection con = this
try
CallableStatement cstm = con
cstm
cstm
//得到返回值
ret = cstm
System
cstm
con
} catch (SQLException e)
// TODO Auto
e
}
}
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28246.html