JAVA通過呼叫資料庫函式呼叫儲存過程
阿新 • • 發佈:2019-02-02
package com.ljq.test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
publicclass ProceTest {
publicstaticvoid main(String[] args) throws Exception {
Connection conn =null;
CallableStatement statement =null;
//?表示函式return的值, stu_proc是資料庫函式名
//儲存過程的out和in都是以引數傳進,這就是函式和儲存過程的區別之一 String sql ="{?=call stu_proc(?)}";
try {
conn = ConnUtils.getConnection();
statement = conn.prepareCall(sql);
statement.registerOutParameter(1, Types.VARCHAR);
statement.setInt( 2, 36);
statement.execute();
//具體值或資料未找到 String msg=statement.getString(1);
System.out.println(msg);
} catch (SQLException e) {
e.printStackTrace();
} finally {
ConnUtils.free(null, statement, conn);
}
}
}