调用存储函数
package demo.oracle;
import java.sql.CallableStatement;
import java.sql.Connection;
import org.junit.Test;
import demo.utils.JDBCUtils;
import oracle.jdbc.internal.OracleTypes;
public class TestFunction {
@Test
public void testFunction() {
String sql = "{?=call getsal(?)}";
Connection conn = null;
CallableStatement call = null;
try {
conn = JDBCUtils.getConnection();
call = conn.prepareCall(sql);
call.registerOutParameter(1, OracleTypes.NUMBER);
call.setInt(2,7839);
call.execute();
double income = call.getDouble(1);
System.out.println(income);
}catch(Exception e) {
e.printStackTrace();
}finally {
JDBCUtils.release(conn, call, null);
}
}
}
在应用程序中访问存储函数
输出参数 可以用 ?表示 {?= call queryempIncome(?)}
2
1