eclipse中显示是下面这行代码错了,并在oracle下面有红线。。。 cs.registerOutParameter(2,oracle.jdbc.OracleTypes.VARCHAR);
import java.sql.*;
public class testorc{
public static void main(String[] args){
try{
//1.加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//2.得到连接
Connection ct = DriverManager.getConnection("jdbc:oracle:thin@127.0.0.1:1521:MYORA1","scott","m123");
//看看如何调用有返回值的过程
//3.创建CallableStatement
CallableStatement cs = ct.prepareCall("{call proc4(?,?)}");
//4.给第?赋值
cs.setInt(1,10);
//给第二个?赋值
cs.registerOutParameter(2,oracle.jdbc.OracleTypes.VARCHAR);
//5.执行
cs.execute();
//得到结果集
ResultSet rs=(ResultSet)cs.getObject(2);
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
} catch(Exception e){
e.printStackTrace();
} finally{
//6.关闭各个打开的资源
}
}
}
------解决方案--------------------
cs.registerOutParameter(2,oracle.jdbc.OracleTypes.VARCHAR);
==>
cs.registerOutParameter(2,Types.VARCHAR);
------解决方案--------------------
LZ要用用java.sql.Types;
------解决方案--------------------
1.第6个参数是游标的话,如下:
cs.registerOutParameter(6,Types.CURSOR);
==>
cs.registerOutParameter(6,oracle.jdbc.OracleTypes.CURSOR);
2.第6个参数是字符串的话,如下:
cs.registerOutParameter(6,Types.CURSOR);
==>
cs.registerOutParameter(2,Types.VARCHAR);
代码迷推荐解决方案:oracle存储过程,http://www.daimami.com/oracle-develop/177537.html