用hibernate操作數據庫
java調用存儲過程
存儲過程是指保存在數據庫並在數據庫端執行的程序
try{
int age =
String poetName =
CallableStatement proc = connection
proc
proc
cs
}catch (SQLException e){ //
傳給prepareCall方法的字串是存儲過程調用的書寫規范
所以CallableStatement類有類似getResultSet這樣的方法來獲取返回值
connection
CallableStatement proc = connection
proc
proc
cs
int age = proc
static void sendEarlyDeaths(PrintWriter out){
Connection con = null;
CallableStatement toesUp = null;
try {
con = ConnectionPool
// PostgreSQL needs a transaction to do this
setAutoCommit(false); // Setup the call
CallableStatement toesUp = connection
toesUp
toesUp
ResultSet rs = (ResultSet) toesUp
while (rs
String name = rs
int age = rs
out
}
rs
}
catch (SQLException e) { // We should protect these calls
}
}
因為JDBC並不直接支持從存儲過程中返回游標
From:http://tw.wingwit.com/Article/program/Java/ky/201405/30833.html