JAVA 调用存储过程 5
Stringsql="{callpro_projectSchedule(?,?,?)}";callStatement=conn.prepareCall(sql);call...
String sql = "{call pro_projectSchedule(?,?,?)}";
callStatement = conn.prepareCall(sql);
callStatement.registerOutParameter(1, Types.VARCHAR);
callStatement.registerOutParameter(2, Types.FLOAT);
callStatement.registerOutParameter(3, Types.FLOAT);
boolean hasResult = callStatement.execute();
System.out.println(hasResult);
System.out.println(callStatement.getString(1));
输出结果竟然是
false
安庆市金土工程建设(一期)
既然没有结果集了,怎么还能从里面取出值呢? 展开
callStatement = conn.prepareCall(sql);
callStatement.registerOutParameter(1, Types.VARCHAR);
callStatement.registerOutParameter(2, Types.FLOAT);
callStatement.registerOutParameter(3, Types.FLOAT);
boolean hasResult = callStatement.execute();
System.out.println(hasResult);
System.out.println(callStatement.getString(1));
输出结果竟然是
false
安庆市金土工程建设(一期)
既然没有结果集了,怎么还能从里面取出值呢? 展开
2个回答
展开全部
//存储过程create or replace Procedure countBySal(
p_sal emp.sal%type,
p_count OUT number
)as
begin
select count(*) into p_count from emp where sal >= p_sql;
end countBySal; //调用步奏import java.sql.CallableStatement; //带哦用存储过程所必须的语句借口
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;public class EmpUtil {
public static int countBySal(double sal) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:test";
Connection cn=DriverManager.getConnection(url, "scott", "tiger");
String sql="{call countBySal(?,?)}";//调用存储过程的语句,call后面的就是存储过程名和需要传入的参数
CallableStatement cst=cn.prepareCall(sql);
cst.setDouble(1, sal);//设置in参数的值
cst.registerOutParameter(2, Types.INTEGER);//注册out参数的类型
cst.execute();
int result = cst.getInt(2);
cst.close();
cn.close();
return result;
}
public static void main(String[] args) {
int count;
try {
count = EmpUtil.countBySal(3000);
System.out.println("工资在3000元以上的人数为:"+count);
} catch (Exception e) {
e.printStackTrace();
}
}
}
p_sal emp.sal%type,
p_count OUT number
)as
begin
select count(*) into p_count from emp where sal >= p_sql;
end countBySal; //调用步奏import java.sql.CallableStatement; //带哦用存储过程所必须的语句借口
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;public class EmpUtil {
public static int countBySal(double sal) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:test";
Connection cn=DriverManager.getConnection(url, "scott", "tiger");
String sql="{call countBySal(?,?)}";//调用存储过程的语句,call后面的就是存储过程名和需要传入的参数
CallableStatement cst=cn.prepareCall(sql);
cst.setDouble(1, sal);//设置in参数的值
cst.registerOutParameter(2, Types.INTEGER);//注册out参数的类型
cst.execute();
int result = cst.getInt(2);
cst.close();
cn.close();
return result;
}
public static void main(String[] args) {
int count;
try {
count = EmpUtil.countBySal(3000);
System.out.println("工资在3000元以上的人数为:"+count);
} catch (Exception e) {
e.printStackTrace();
}
}
}
追问
能不能看看我的代码,你这通篇的复制,只会浪费大家的时间,没有任何意义
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询