Skip site navigation (1) Skip section navigation (2)

JDBC: getUpdateCount always at least one?

From: Jim Wise <jwise(at)draga(dot)com>
To: pgsql-interfaces <pgsql-interfaces(at)postgreSQL(dot)org>
Subject: JDBC: getUpdateCount always at least one?
Date: 2000-02-21 17:28:55
Message-ID: Pine.NEB.4.21.0002211217170.10855-100000@himring.draga.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am writing a program which uses the Statement.execute() method to
execute arbitrary SQL statements, and uses ResultSetMetaData to parse
the resulting result set.  Now, when Statement.execute() returns false,
it means that there is no result set, but that Statement.getUpdateCount()
can be used to get a count of how many rows were affected by the SQL
statement.  In the update, insert and delete cases this works fine, but
I've found that when passing in a null query, or a query whose WHERE
clause prevents it from affecting any rows, getUpdateCount is still
returning 1.

This is with the version of the JDBC driver which shipped with 6.5.3,
under JDK 1.1.8.

Is this normal, is it a know problem, or is it something I'm doing
wrong?  The code in question looks basically like this:

	private void doRequest (String req)
	{
            try {
                java.sql.Statement s = conn.createStatement();
	
	[...]

		if(s.execute(req))
                {

	[...]

		} else {
                        rowsTouched = s.getUpdateCount();
                }
	    } catch (Exception e) {
                out.println("<PRE>");
                e.printStackTrace(out);
                out.println("</PRE>");
            }
	}

- -- 
				Jim Wise
				jwise(at)draga(dot)com

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBOLF13i2NgFbJL33VEQJ/wQCgycyF7I7nLNTiSx7GAgvEZ08D2/YAn0mY
G3eBRIpdqcwENIvq4xfntHEc
=Z7GV
-----END PGP SIGNATURE-----


pgsql-interfaces by date

Next:From: richard clarkDate: 2000-02-21 17:57:49
Subject: subscribe
Previous:From: richard clarkDate: 2000-02-21 16:03:11
Subject: SUBSCRIBE

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group