cancelled at the user's request



Hi

I'm writng a servlet to maintain a database of users.

One functionality is to add/amend a user. The sql
steps I go through are

1) A simple select to see if the supplied community exists

2) delete the user if exists

3) add user with new attributes (passwd,firstname,lastname etc)

I'm turning off autocommit and only committing at the end
if no exceptions encountered

I'm inconsistently getting the exception
"[Microsoft][SQLServer 2000 Driver for JDBC]The operation
was cancelled at the user's request"

Most of the time it's working but occaisonally it doesn't.
Part of the problem might be that I'm setting the querytimeout
but it's set to 10 minutes and the process finishes in under
a second. If I remove the querytimeout I've yet to encounter the
exception but not sure if this is luck. Ideally I'd like
to keep the timeout in and/or understand what's happening.

Code snippets below. During a run of getting the exceptions
yesterday it was occuring at the con.commit point. Worryingly
the excpetion was thrown but the database was updated, is this
possible.

I tried doing the sql as separate executes rather than batch
but moving to batch seems to reduce the frequency of errors.

thanks
Mike

con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.setQueryTimeout(90);
......
stmt.execute("select * from wsa_community where community='"
+ community + "'");
ResultSet rs = stmt.getResultSet();
boolean communityExists = false;
if (rs.next()) {
communityExists = true;
}
rs.close();
if (communityExists) {
String sqlAddUser;
String sqlDelUser;
sqlDelUser = "delete from wsa_users where username='"
+ userName+ "'and community='"+ community+ "'";
stmt.addBatch(sqlDelUser);
sqlAddUser = "insert into wsa_users
(lastName,firstName,username,community,password) values ( "
+ "'"+ lastName+ "',"
+ "'"+ firstName+ "',"
+ "'"+ userName+ "',"
+ "'"+ community + "'," + "'" + passwd1 + "')";
stmt.addBatch(sqlAddUser);
int resCount[];
resCount=stmt.executeBatch();
.......
stmt.close();
con.commit();
.....
con.close();

.



Relevant Pages

  • Re: PEAR DB - Useful?
    ... SQL, all I have to do is change the connect string and I can use it to ... work with more or less any database out there. ... PHP5's exceptions and stuff, ... debugging information in a log file. ...
    (comp.lang.php)
  • Re: cancelled at the users request
    ... Microsoft, SQL Server ... During a run of getting the exceptions ... > boolean communityExists = false; ... > String sqlAddUser; ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Embedded SQL in C#
    ... You can either handle specific exceptions or ... to the database access layer, stored procedures, ... > is noble, I would rather have embedded SQL, for all the reasons above. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Returning validation result from method: exception, status code...?
    ... Duplicate keys in the database sounds like Exceptions to me. ... Also I would verify there was not a clash before I called the CreateUser ... and returns the newly created UserID: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SqlDataAdapter Update Method wont work
    ... Are you trying to update in the event handler for a UI component? ... However, when I issue the command to update the database, ... No errors, no exceptions. ... I let the Wizard generate the Update Command code. ...
    (microsoft.public.dotnet.languages.csharp)