0

I am trying to delete SWT table row using SWT/Jface datadinding to DB through ibatis implementation.

I am getting below exception whenever i try to do insert or delete operation from client side (SWT).

org.apache.ibatis.exceptions.PersistenceException: 
### Error committing transaction.  Cause: java.sql.SQLException: database is locked

This doesn't happen when i try to hit DB (SQLite) through ibatis directly.

Below is the code section for delete operation i am doing with SWT button and trying to delete SWT table row.

SWT Code....

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
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
Prashant P
  • 21
  • 4

1 Answers1

0

From your description and related question before, I think you are trying to access SQLite database in different threads at the same time. Button event handler code is running inside of SWT UI thread. You may have other code trying to connect to database in other threads.

Community
  • 1
  • 1
Fu Cheng
  • 3,385
  • 1
  • 21
  • 24
  • Yes you are true Alex... I am using SQLite and Ibatis. Is there any way to resolve this...since i am not using JDBC directly...instead using ibatis.So how can i make sure Single connection...instead of going through multiple DB connection. – Prashant P Nov 14 '12 at 00:52
  • I have added below tag to make sure i have single active connection in sqlmap configuration, – Prashant P Nov 16 '12 at 07:22