我试图通过ibatis实现使用SWT / Jface数据绑定删除SWT表行。
每当我尝试从客户端(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
答案 0 :(得分:0)
从您的描述和related question之前,我认为您正在尝试同时在不同的线程中访问SQLite数据库。 Button事件处理程序代码在SWT UI线程内运行。您可能有其他代码尝试连接到其他线程中的数据库。