JAVAsql。SQLException:在SWT中使用时数据库被锁定
我正试图通过ibatis实现,使用SWT/Jface Datading将SWT表行删除到DB
每当我尝试从客户端(SWT)执行插入或删除操作时,我都会遇到以下异常
org.apache.ibatis.exceptions.PersistenceException:
### Error committing transaction. Cause: java.sql.SQLException: database is locked
当我试图通过ibatis直接访问DB(SQLite)时,这种情况不会发生
下面是我正在使用SWT按钮执行的删除操作的代码部分,我正在尝试删除SWT表行
SWT代码
btnDeleteWorkspaceRow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) m_workplaceViewer.getSelection();
WorkplaceDetail workplaceDetail = (WorkplaceDetail) selection.getFirstElement();
boolean confirm = MessageDialog.openConfirm(shell, "Confirm Delete", "Are you sure you want to delete row"+ + workplaceDetail.getCode() + "'?");
if (confirm) {
**int code =186;** (Hardcoded row value- actual DB row number)
WorkplaceDaoImpl workplaceDaoImpl = new WorkplaceDaoImpl();
try {
**WorkplaceDaoImpl.deleteWorkplaceDetail(code);**
} catch (SQLException e1) {
e1.printStackTrace();
}
m_bindingContext.updateModels();
}
}
});
This is Ibatis DAO implementation code which i am invoking in SWT
**WorkplacseDaoImpl.java**
public void deleteWorkplaceDetail(int code)
throws SQLException {
SqlSession session = sqlSessionFactory.openSession();
session.delete("WorkplaceDetail.deleteWorkplaceById", code);
session.commit();
session.close();
}
**Ibatis Configuration**
<delete id="deleteWorkplaceById">
delete from Workplace where workplaceCode=#{code}
</delete>
Please help me to resolve this issue. I am using SQLite DB
# 1 楼答案
从您的描述和之前的related question来看,我认为您试图同时在不同的线程中访问SQLite数据库。按钮事件处理程序代码正在SWT UI线程内运行。您可能有其他代码试图在其他线程中连接到数据库