i trying delete column in sqlite database table using jdbc. there no such function in sqlite, achieve this, used approach:
- create new table (
t1_backup
) columns not 1 deleted, - copy data (except of column deleted) new table,
- drop old table (
t1
), - rename new table (
t1_backup
-->t1
).
the actual code follows:
connection cn = drivermanager.getconnection("jdbc:sqlite:"+path); statement stmt = new statement(); stmt = cn.createconnection(); stmt.execute("create table t1_backup(id);"); stmt.executeupdate("insert t1_backup select id t1;"); stmt.execute("drop table t1;"); stmt.execute("alter table t1_backup rename t1;");
the first 2 statements executed without problem. when drop table statement executed, gave me java.sql.sqlexception: [sqlite_locked] table in database locked (database table locked)
.
i have found solution not sure why worked. solution create 3 more statement objects, connect them same database , execute each of 4 sql statements different statement object:
stmt.execute("create ..."); stmt2.executeupdate("insert ..."); stmt3.execute("drop ..."); stmt4.execute("alter ...");
can explained?
the jdbc using 1 xerial.
thank you.
Comments
Post a Comment