samedi 28 novembre 2015

SQLITE Database is locked in Java (Eclipse)

When I try to update (or replace) records in my database it shows "Database is locked" error!

For example, this button should update the user's account details:

 JButton btnUpdate = new JButton("Update");
 btnUpdate.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {

          Connection connection3 = SqliteConnection.dbConnector();
          PreparedStatement pst1 = null;

        try {

            String q1 = "replace into Users (FullName,UserName,Email,Password,Question,Answer,UserType) values('"+FullName.getText()+"' ,'"+MainPage.getAuthUser()+"' , '"+Email.getText()+"', '"+Pass.getPassword().toString()+"' , '"+Question.getSelectedItem().toString()+"' , '"+Answer.getText()+"' , '"+UserType.getSelectedItem().toString()+"') ";
          //String q1 = "update Users FullName = '"+FullName.getText()+"' where UserName like '"+MainPage.getAuthUser()+"'  ";
            pst1 = connection3.prepareStatement(q1);

            pst1.executeUpdate();
            pst1.close();
            connection3.close();

        } catch (SQLException e6) {
            JOptionPane.showMessageDialog(null, e6);
        }
    }
});

I've used the same connection for inserting records (create account) and for selecting some of them (login) and those buttons work fine.

I even have tried closing both, connection and statement, in a finally block,but still not working.

Aucun commentaire:

Enregistrer un commentaire