5. After calling the stored procedure using the sqlservercallablestatement class, you can call the stored procedure using any of the execute or executeupdate methods. The executeupdate method returns an int value that contains the number of rows affected by the stored procedure, but the execute method does not return this value. If you use the execute method and want to obtain the affected number of rows, you can call the getupdatecount method after running the stored procedure. As an instance, create the following tables and stored procedures in the SQL Server 2005 adventureworks sample database:
SQL code: Create Table testtable
(Col1 int identity,
Col2 varchar (50 ),
Col3 INT );
Create procedure updatetesttable
@ Col2 varchar (50 ),
@ Col3 int
As
Begin
Update testtable
Set col2 = @ col2, col3 = @ col3
End;
In the following example, the open connection of the adventureworks sample database will be passed to this function, and the updatetesttable stored procedure will be called using the execute method, and the row count affected by the stored procedure will be returned using the getupdatecount method.
Java code public static void executeupdatestoredprocedure (connection con ){
Try {
Callablestatement cstmt = con. preparecall ("{call DBO. updatetesttable (?, ?)} ");
Cstmt. setstring (1, "");
Cstmt. setint (2,100 );
Cstmt.exe cute ();
Int COUNT = cstmt. getupdatecount ();
Cstmt. Close ();
System. Out. println ("rows affected:" + count );
}
Catch (exception e ){
E. printstacktrace ();
}
}
From: http://www.cn-java.com/www1? Action-viewnews-itemid-55626