cancelled at the user's request
- From: "Mikee" <mar@xxxxxxxxx>
- Date: 1 May 2005 08:33:20 -0700
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();
.
- Follow-Ups:
- Re: cancelled at the user's request
- From: Shelby Goerlitz [MSFT]
- Re: cancelled at the user's request
- Next by Date: Re: SelectMethod=cursor and SelectMethod=direct
- Next by thread: Re: cancelled at the user's request
- Index(es):
Relevant Pages
|