• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i lock database programmatically?

 
rahul kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, disregard the above comments. I didn't realize I was posting a response to such an old question.
Thanks.
Craig.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic