tags:

views:

84

answers:

2

can we work with multiple tables of database with same connection object of database at same time .

suppose i have inserted value in table 1 and at same time also inserted value in table 2 of data base with same object of data base connection.

I am using sqlite database in code and getting database locked exception while commit() .

A: 

Any transaction locks the complete database. You cannot access the sqlite database during any ongoing transaction.

Aseem Gautam
I got following exception ,is this related to database locked exception or it may cause to database locked exception Exception:call() called in inappropriate state stacktrace java.lang.IllegalStateException: call() called in inappropriate state at org.ibex.nestedvm.Runtime.call(Runtime.java:655) at org.ibex.nestedvm.Runtime.call(Runtime.java:647) at org.sqlite.NestedDB.call(NestedDB.java:406) at org.sqlite.NestedDB.call(NestedDB.java:389) at org.sqlite.NestedDB.reset(NestedDB.java:135) at org.sqlite.RS.close(RS.java:98)
rajkumari
or is database locked exception occurred due to obj Connection.commit() line
rajkumari
Locked exception pretty much means that DB is in use. You must be using some wrapper library for db operations, check its documentation in case you are missing something. And update post with code.
Aseem Gautam
A: 

You need one statement per table, all using the same connection:

INSERT INTO t1(x, y, z) VALUES(1, 2, 4);
INSERT INTO t2(a, b, c) VALUES("FOO", "BAR", 2.1);

These should be inserted as a single unit of work.

If you're inserting values from the same object, you're probably doing something wrong. "Say It Once and Only Once" suggests that there shouldn't be a need to save the same value in two different tables. I'd INSERT it once and use a trigger to put it in a history table or something like that.

duffymo
I got following exception ,is this related to database locked exception or it may cause to database locked exception Exception:call() called in inappropriate state stacktrace java.lang.IllegalStateException: call() called in inappropriate state at org.ibex.nestedvm.Runtime.call(Runtime.java:655) at org.ibex.nestedvm.Runtime.call(Runtime.java:647) at org.sqlite.NestedDB.call(NestedDB.java:406) at org.sqlite.NestedDB.call(NestedDB.java:389) at org.sqlite.NestedDB.reset(NestedDB.java:135) at org.sqlite.RS.close(RS.java:98)
rajkumari
Don't know. Post some code.
duffymo