import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
public class PageCallTest {
// 调用一个无返回值的过程
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott", "tiger");
/*CallableStatement cs = conn.prepareCall({"call sp_pro7(?,?,?)"});
cs.setInt(1,10);
cs.setString(2, "笑傲江湖");
cs.setString(3, "人民出版社");*/
//看看如何調用有返回值的存儲過程
CallableStatement cs = conn.prepareCall("{call sp_pro8(?,?)}");
cs.setInt(1, 7788);
//給第二個?賦值
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.VARCHAR);
cs.execute();
//取出返回值,要注意?的順序
String name = cs.getString(2);
System.out.println("7788的名字:" + name);
cs.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}