Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

getUpdateCount()

2 posts in JDBC Connect (product renamed to JConnect) Last posting was on 1997-04-28 18:11:38.0Z
Ellen Carroll Posted on 1997-04-25 23:28:34.0Z
Message-ID: <33613E22.6AC5@raba.com>
Date: Fri, 25 Apr 1997 19:28:34 -0400
From: Ellen Carroll <ellen.carroll@raba.com>
Reply-To: ellen.carroll@raba.com
Organization: RABA Technologies
X-Mailer: Mozilla 3.0Gold (Win95; U)
MIME-Version: 1.0
Subject: getUpdateCount()
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 32
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:925
Article PK: 252676

When I run the IsqlApp using a simple select statement, the
getUpdateCount() returns a non-negative number for "rows affected."
From my own application, if I execute a stored procedure, I get only
results sets and no "rows affected." Does the getUpdateCount() method
apply to stored procedures? If so, under what conditions should
getUpdateCount() return something other than a -1?

This is under jdk 1.1.1., jConnect version 2.0.
A code fragment follows.

Connection con;
.
.
.
cstmt = con.prepareCall("{? = call SelectFoo(?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setString(2, "myFoo");

boolean results = cstmt.execute();
int rowsAffected = 0;
do {
if (results) {
// do something useful with the results

}
else {
rowsAffected = cstmt.getUpdateCount();
if (rowsAffected >= 0) {
System.out.println(rowsAffected +
" rows Affected.");
}
}
} while (results || rowsAffected != -1)
.
.
.

+++++++++++++

% java Version
Using JDBC driver version 2.0

jConnect (TM) for JDBC (TM)/2.0/Production Version/JDK11/Thu Mar 13
14:34:32 1997

+++++++++++++

%java -version
java version "1.1.1"

+++++++++++++

Thanks,

Ellen


David Clegg Posted on 1997-04-28 18:11:38.0Z
Message-ID: <3364E85A.727BEBE0@sybase.com>
Date: Mon, 28 Apr 1997 11:11:38 -0700
From: David Clegg <davec@sybase.com>
X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i586)
MIME-Version: 1.0
To: ellen.carroll@raba.com
Subject: Re: getUpdateCount()
References: <33613E22.6AC5@raba.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 61
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:908
Article PK: 252660

SQL-Server doesn't report the "rows affected" information in the
same way with stored procedures as it does for straight language
commands (select or searched updates), and thus the jConnect driver
cannot make that information available to your application through
the getUpdateCount() method.

You can use the @@rowcount T/SQL variable to retrieve this data
(sort of a pain to have to re-write your stored procedure, but...)

create procedure SelectFoo(@p1 VARCHAR(30), @rows int OUTPUT) as
begin
delete from tfoo where c1 = @p1
select @rows = @@rowcount
return 1
end

Then use:
cstmt.registerOutputParameter(2, Types.INTEGER);
...
rowsAffected = cstmt.getInt(2);

to get the value.

dave

> When I run the IsqlApp using a simple select statement, the
> getUpdateCount() returns a non-negative number for "rows affected."
> From my own application, if I execute a stored procedure, I get only
> results sets and no "rows affected." Does the getUpdateCount() method
> apply to stored procedures? If so, under what conditions should
> getUpdateCount() return something other than a -1?
>
> This is under jdk 1.1.1., jConnect version 2.0.
> A code fragment follows.
>
> Connection con;
> .
> .
> .
> cstmt = con.prepareCall("{? = call SelectFoo(?)}");
> cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
> cstmt.setString(2, "myFoo");
>
> boolean results = cstmt.execute();
> int rowsAffected = 0;
> do {
> if (results) {
> // do something useful with the results
>
> }
> else {
> rowsAffected = cstmt.getUpdateCount();
> if (rowsAffected >= 0) {
> System.out.println(rowsAffected +
> " rows Affected.");
> }
> }
> } while (results || rowsAffected != -1)
> .
> .
> .
>
> +++++++++++++
>
> % java Version
> Using JDBC driver version 2.0
>
> jConnect (TM) for JDBC (TM)/2.0/Production Version/JDK11/Thu Mar 13
> 14:34:32 1997
>
> +++++++++++++
>
> %java -version
> java version "1.1.1"
>
> +++++++++++++
>
> Thanks,
>
> Ellen