EDIT :: closing resultset and statements for queries solved the problem for me
I am trying to build a chat app by java and sqlite. when i try to insert a new record to a table in data base i am facing data base locked error message. here i try to add new user when they sign up first time:
public void addNewUser(String username,String password) {
StringBuilder sb=new StringBuilder("INSERT INTO loginInfo VALUES('");
sb.append(username);
sb.append("','");
sb.append(password);
sb.append("')");
try {
Statement statement = connection.createStatement();
statement.execute(sb.toString());
statement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
i am first checking if already same username existed in doesUserExist() function:
private void handleSignup(String[] tokens) throws IOException, SQLException {
if(tokens.length==3){
String username=tokens[1];
String password=tokens[2];
String msg=null;
if(!dataSource.doesUserExists(username)) {
msg="signup successful\n";
this.login=username;
dataSource.addNewUser(username,password);
}
else msg="signup unsuccessful\n";
this.send(msg);
}
}
i get this following error message:
org.sqlite.SQLiteException: [SQLITE_BUSY] The database file is locked (database is locked)
at org.sqlite.core.DB.newSQLException(DB.java:1010)
at org.sqlite.core.DB.newSQLException(DB.java:1022)
at org.sqlite.core.DB.execute(DB.java:861)
at org.sqlite.core.CoreStatement.exec(CoreStatement.java:80)
at org.sqlite.jdbc3.JDBC3Statement.execute(JDBC3Statement.java:53)
i have closed the statement after execution of all other queries. what can i do to solve this bug?