- 论坛徽章:
- 0
|
好的。
就现在我知道情况是这样的,对于Oracle,getUpdateCount是可以可以得到Update语句影响的记录数,但只能是直接的Update语句执行(如3楼的帖子),而不能是调用包含Update语句的存储过程(如1楼的帖子)。
如果既要调用含有Update语句的存储过程,又要得到该Update语句影响的记录数,就得用Out输出参数了。
下面是我对1楼和3楼的程序修改之后的情况:
SQL> select text from user_source where name='TMP_U';
TEXT
--------------------------------------------------------------------------------
procedure tmp_u(v_id tmp.id%type,v_rowcount out integer)
as
begin
update tmp set value = 'aa' where id >= v_id;
v_rowcount := sql%rowcount; ----- 得到前一条DML语句所影响的行数
end;
import java.sql.* ;
public class dbtest {
public static void main(String[] args) throws SQLException {
String className,url,uid,pwd;
className = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@192.168.1.8:1521:TBTDB";
uid = "scott";
pwd = "tbtscott2006";
Connection conn=null;
CallableStatement proc1 = null;
CallableStatement proc2 = null;
int c=-999;
int x=5;
try
{
Class.forName(className);
conn = DriverManager.getConnection(url,uid,pwd);
proc1 = conn.prepareCall("{ call tmp_i() }");
proc1.execute();
proc1.close();
proc2 = conn.prepareCall("{ call tmp_u(?,?)}");
proc2.setInt(1,x);
proc2.registerOutParameter(2,java.sql.Types.INTEGER);
proc2.execute();
c=proc2.getInt(2);
proc2.close();
System.out.println(c);
System.out.println("OK");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("ERROR");
System.out.print(e.getMessage());
}
finally
{
conn.close();
}
}
} |
|