A
A
AwvuweWd2019-05-16 11:18:57
Java
AwvuweWd, 2019-05-16 11:18:57

How to check DB lock?

You need to check the database lock.
(I want to check for a running copy, I took the direction to check the database) I run copy
1, the database is blocked, let's say I run copy 2, it connects to the sqlite database (which is busy) (here you need to check)
here is the connection
Class.forName("org.sqlite .jdbc");
conn = DriverManager.getConnection("jdbc:sqlite:db.s3db");
here is the exception to check:
org.sqlite.SQLiteException: [SQLITE_BUSY] The database file is locked (database is locked)
at org.sqlite.core.DB.newSQLException(DB.java:941)
at org.sqlite.core. DB.newSQLException(DB.java:953)
at org.sqlite.core.DB.throwex(DB.java:918)
at org.sqlite.core.NativeDB._exec_utf8(Native Method)
at org.sqlite.core.NativeDB._exec(NativeDB.java:94)
at org.sqlite.jdbc3.JDBC3Statement.executeUpdate(JDBC3Statement.java:109)
...
at java.base/java.lang.Thread.run( Thread.java:834)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AwvuweWd, 2019-10-14
@AwvuweWd

I caught the exception
org.sqlite.SQLiteException: [SQLITE_BUSY] The database file is locked (database is locked)

D
Dmitry Eremin, 2019-05-16
@EreminD

is this a unit test?

@Test
    public void dbLockTest() {
        try {
            //тут ваш код котрый должен выбросить исклчение
            connectToDb();

             //если ваш код не выбросит исключения, то помечаем тест как failed()
            fail("Didn't throw any exception");
        } catch (Exception ex) {
            assertThat(ex, instanceOf(SQLiteException.class));
            assertThat(ex.getMessage(), equalTo("[SQLITE_BUSY] The database file is locked (database is locked)"));
          }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question