Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:41:30+00:00 2026-05-27T15:41:30+00:00

I am trying to lock a table in my testing framework in order to

  • 0

I am trying to lock a table in my testing framework in order to trigger timeouts. I am using the following code to lock the table.

String lock = "lock table "+ tableName +" in exclusive mode";
try {
        connection = DriverManager.getConnection(_url, _username, _password);
        connection.setAutoCommit(false);  
        Statement stmt1=connection.createStatement();  
        stmt1.executeUpdate(lock);  

    } catch (SQLException e) {
        e.printStackTrace();
    }

After I have executed this I try to access the page and add an element to the account. However it doesn’t work, the lock doesn’t seem to have occurred. Any idea why this wouldn’t work? I am currently testing this in java and once I have executed that lock I am sleeping the thread while manually testing the page, could this be causing problems?

Thanks,
James

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:41:31+00:00Added an answer on May 27, 2026 at 3:41 pm

    The oracle’s documentation say:

    You use the LOCK TABLE statement to lock entire database tables in a
    specified lock mode so that you can share or deny access to them.. Row
    share locks allow concurrent access to a table; they prevent other
    users from locking the entire table for exclusive use. Table locks are
    released when your transaction issues a commit or rollback.

    So you need to start a transaction and maintain it. The following code maintains the table locked for one minute:

    String lock = "lock table "+ tableName +" in exclusive mode";
    try {
        connection = DriverManager.getConnection(_url, _username, _password);
        connection.setAutoCommit(false);  
        Statement stmt1=connection.createStatement();  
        stmt1.execute(lock);  
        int i = 0;
        while (i<60) {            
            Thread.sleep(1000);    //Sleep one second
            i++;                   
        }
        connection.commit();
    
    } catch (SQLException e) {
        connection.rollback();
        e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove the need to explicitly lock a table with the following
I'm trying to create a persistent SQL (SQL Server 2005) lock on a table
i'm trying to lock a row in a db-table when a user is editing
I am trying to figure out how to lock an entire table from writing
I am trying to restore the database file(backup.sql) using c# by the following method...
So I am trying to lock an isolated storage file in my C# client
I'm trying to toggle caps lock on/off when the two shift buttons are held
I am trying to create a program similar to Folder Lock which prevents users
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.