J'ai la dbConnection folowingcomment vérifier si une connexion à une base de données existe dans sqlite en utilisant java?
public class DBConnection {
protected Statement statement;
protected Connection connection = null;
public DBConnection() {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
connection = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\ion\\Desktop\\sample.db");
statement = connection.createStatement();
statement.setQueryTimeout(30);
statement.executeUpdate("CREATE TABLE IF NOT EXISTS person (id STRING PRIMARY KEY NOT NULL,"
+ "name STRING, email STRING UNIQUE, password STRING)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS message (id STRING PRIMARY KEY NOT NULL,"
+ "text STRING, subject STRING, dateMessage Date, parrentMessageId String , personId String, "
+ "categoryId String,"
+ " FOREIGN KEY(personId) REFERENCES person(id),FOREIGN KEY(categoryId) REFERENCES category(id))");
statement.executeUpdate(
"CREATE TABLE IF NOT EXISTS category (id STRING PRIMARY KEY NOT NULL," + "name STRING)");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
mais si je l'utilise dans un Servlet comme celui-ci
String id = personService.getIdByEmail(email);
message.setPersonId(id);
messageService.persist(message);
et je demande des services deux fois différents qui appelle les différents référentiels (personRep et messageRep à la fois étendre cette classe DbConnection) Il me donne "database is locked"
Comment vérifier si une connexion existe déjà? S'il vous plaît aidez-moi ..Merci !!
Quelque chose comme ça? synchronisée (lock1) { \t \t \t \t \t \t \t \t connection = DriverManager.getConnection ("jdbc: sqlite: C: \\ ion \\ \\ Les utilisateurs de la sample.db de bureau"); \t \t \t \t instruction = connection.createStatement(); \t \t \t \t instruction.setQueryTimeout (30); – joesid