0

我正在尝试使用 SWT/Jface 数据通过 ibatis 实现删除 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
4

1 回答 1

0

从您之前的描述和相关问题来看,我认为您正试图同时在不同的线程中访问 SQLite 数据库。按钮事件处理程序代码在 SWT UI 线程内运行。您可能有其他代码尝试在其他线程中连接到数据库。

于 2012-11-13T09:23:54.673 回答