Posted by Erland Sommarskog on 12/07/05 00:34
Sandy (a@a.com) writes:
> I want to lock a table using JDBC as I want to perform some query's (read
> and write) in exclusive mode. Different threads will be executing the same
> code simultaneously. I am using the following statements
>
> Statement stmt = connection.createStatement();
> stmt.executeUpdate("lock table STATUS_TBL in EXCLUSIVE mode");
>
> but am getting the following error
> [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect
> syntax near 'STATUS_TBL'.
>
>
> can somebody tell the correct syntax for the lock table statement.
There isn't one. There simply is no LOCK TABLE in Microsoft SQL Server.
Other products may have this command, but I don't think is ANSI SQL.
Anyway, the thing to use for this purpose in SQL Server is application
locks. Check out sp_setapplock in Books Online.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|