Article View: borland.public.jbuilder.database
Article #356Re: MS SQLServer "FOR UPDATE" - update
From: Magnus
Date: Thu, 26 Oct 2006 01:59
Date: Thu, 26 Oct 2006 01:59
37 lines
2361 bytes
2361 bytes
Magnus wrote:
> Hi,
>
> I use the below stmt to do a "lock" on the table.
> It works great on JDS and MySQL but I get the following error on MS SQL
> Server 2000:
>
> e:com.microsoft.sqlserver.jdbc.SQLServerException: Line 1: FOR UPDATE
> clause allowed only for DECLARE CURSOR.
>
> Can anyone point me in the right direction here?
>
> TIA
>
>
> ---
> rs = stmt.executeQuery("select path from location " +
> "where compid = \'" + compId + "\' " +
> "and location = \'" + location + "\' " +
> "FOR UPDATE ");
I managed to get it to work using 2 statements:
stmt.executeUpdate("DECLARE cursor_name CURSOR FOR " +
"select path from location " +
"where compid = \'" + compId + "\' " +
"and location = \'" + location + "\' " +
"FOR UPDATE ");
rs = stmt.executeQuery("select path from location " +
"where compid = \'" + compId + "\' " +
"and location = \'" + location + "\' ");
I don't know if this will lock the rows though.
After I'm done, as part of cleaning up, I "DEALLOCATE cursor_name" to
release everything. Otherwise I got an error the second time I went to
the same setup screen and tried to insert more values ...
Technical Details
Message-ID:
<4540167a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<453fb594$3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1073da,b07ba128b612bb4e X-Google-Attributes: gid1073da,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 25 Oct 2006 21:59:41 -0400 From: Magnus <magnus_bjorkman@yahoo.com> User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.database Subject: Re: MS SQLServer "FOR UPDATE" - update References: <453fb594$3@newsgroups.borland.com> In-Reply-To: <453fb594$3@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.149.234.69 Message-ID: <4540167a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1161827962 24.149.234.69 (25 Oct 2006 18:59:22 -0700) Lines: 37 Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail