Fehler: org.sqlite.SQLiteException: [SQLITE_BUSY] Die Datenbankdatei ist gesperrt (Datenbank ist gesperrt)
immer wenn ich überprüfe, ob ein Benutzername eindeutig ist, und ihn anschließend meiner Datenbank hinzufüge. Ich verwende Java, JSP und JDBC.
Verbindung und Abfragen:
Code: Select all
public class UserDao {
private static Connection conn = null;
public static Connection connect() throws Exception {
if(conn == null) {
conn = (Connection) DriverManager.getConnection("jdbc:sqlite:c:/Users/ryo/database.db");
} else {
conn.close();
conn = (Connection) DriverManager.getConnection("jdbc:sqlite:c:/Users/ryo/database.db");
}
return conn;
}
private String table;
public UserDao(String table) {
this.table = table;
}
public User findUser(String username) throws SQLException {
PreparedStatement pStmt = conn.prepareStatement("SELECT * FROM " + table + " WHERE Username=?");
pStmt.setString(1, username);
try (
ResultSet rs = pStmt.executeQuery()) {
if(rs.next()) {
return new User(
rs.getString("Name"),
rs.getString("Username"),
rs.getString("Password"),
rs.getBoolean("Admin")
);
}
} catch (Exception e) {
System.out.println("ERROR FINDING USER");
e.printStackTrace();
return null;
}
return null;
}
public long addUser(User user, String password) throws SQLException {
PreparedStatement pStmt = conn.prepareStatement("INSERT INTO " + table + " (Username, Name, Password, Admin) VALUES(?,?,?,?)");
pStmt.setString(1, user.getUsername());
pStmt.setString(2, user.getName());
pStmt.setString(3, password);
pStmt.setBoolean(4, user.isAdmin());
int rowsAdded = pStmt.executeUpdate();
long allocatedId = 0L;
if (rowsAdded == 1) {
ResultSet rs = pStmt.getGeneratedKeys();
if(rs.next()) {
allocatedId = rs.getLong(1);
}
}
return allocatedId;
}
}
Code: Select all
[url=./login.html]
[/url]
[url=./signup.html]
[/url]