wood burning stoves 2.0*
The moose likes JDBC and the fly likes how can i lock database programmatically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how can i lock database programmatically? " Watch "how can i lock database programmatically? " New topic
Author

how can i lock database programmatically?

rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
how can we lock the database programmatically,or through help of some JDBC API methods.I am working with Swing for user interface and JDBC 3.0 for connection to database with JDBC-ODBC bridge.My backend is MS SQL Server.
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
in oracle then it is done like this. try to look for similar queries for ur database.

and when u want to free the lock then u just have to say commit and it is freed.
rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
prabhat commiting means something else but what i want is to lock the database. which means that no two queries can be executed simultaneously. by setAutocommit(false) u can't stop simultaneous execution of queries.
rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
Pls guys and JDBC Gurus i had to complete my software before 31 march. and had done only 10% of coding. pls tell me is there any way to lock the databse through java( like in ASP there are methods for locking and unlocking database 'connection.lock()' & 'connection.unlock()' ) or there is any other way.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

try Connection.setTransactionIsolation(TRANSACTION_SERIALIZABLE);
This sets the level of managing potential conflicts that may arise when 2 transactions are operating on a database to the highest level.
Jamie
[ March 02, 2002: Message edited by: Jamie Robertson ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I could be mistaken, but I don't believe java has a built in mechanism that will lock a database from access. There are utilites that will allow you to control the type of transaction that can occur on the database(read-only, dirty reads etc.). But I believe you may have to build your own database locking mechanism. Creating a locking mechanism at the database level as opposed to the record level is a little easier. I would suggest you look into creating some kind of flag(on/off) locking mechanism.
I hope this helps.
Craig
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Please, disregard the above comments. I didn't realize I was posting a response to such an old question.
Thanks.
Craig.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can i lock database programmatically?
 
Similar Threads
how can i lock database programmatically?
how can i lock database programmatically?
Readonly unmodifiable collection
How to check if triggers are enabled in MS SQL Server database?
JDBC Connection Isolation level query