package demo.oracle;
import java.sql.CallableStatement;
import java.sql.Connection;
import org.junit.Test;
import com.sun.java_cup.internal.runtime.Symbol;
import demo.utils.JDBCUtils;
import oracle.jdbc.driver.OracleTypes;
/*
* Create Or Replace Procedure queryempinform(eno In Number,
* pename Out Varchar2,
* psal Out Number,
* pjob Out Varchar2)
*
*/
public class TestProcedure {
@Test
public void testProcedure(){
//{call <procedre-ane>[(<arg1>,<arg2>,...)]}
String sql="{call queryempinform(?,?,?,?)}";
Connection conn=null;
CallableStatement call=null;
try {
//得到一个连接
conn=JDBCUtils.getConnection();
//通过连接创建statment
call=conn.prepareCall(sql);
//对于in参数,赋值
call.setInt(1,7839);
//对于out参数,申明
//OracleType就是将oracle内所以类型转变成JAVA常量
call.registerOutParameter(2,OracleTypes.VARCHAR);
call.registerOutParameter(3,OracleTypes.NUMBER);
call.registerOutParameter(4,OracleTypes.VARCHAR);
//执行调用
call.execute();
//取出结果
String name = call.getString(2);
double sal =call.getDouble(3);
String job = call.getString(4);
System.out.println(name+"\t"+sal+"\t"+job+"\t");
} catch (Exception e) {
e.printStackTrace();
}finally{
//关闭资源
JDBCUtils.shifang(conn, call, null);
}
}
}
可能是没对取到的值判空吧