는 내가 folowing dbConnection에게java를 사용하여 sqlite에 데이터베이스 연결이 있는지 확인하는 방법은 무엇입니까?
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();
}
}
}
을 가지고 있지만 나는이
String id = personService.getIdByEmail(email);
message.setPersonId(id);
messageService.persist(message);
같은 서블릿에서 사용하고 난 다른 저장소 호출 두 번 다른 서비스를 호출하는 경우 (personRep 및 messageRep을이 DbConnection 클래스를 확장 모두) 그것은 나를주고있다 "database is locked"
연결이 이미 있는지 어떻게 확인합니까? 도와주세요 .. 고마워요 !!
이와 비슷한 기능이 있습니까? 동기 (lock1) { \t \t \t \t \t \t \t \t 연결 = DriverManager.getConnection를 ("JDBC : SQLite는 : C : \\ 사용자 \\ 이온 \\ 화상 \\ sample.db"); \t \t \t \t statement = connection.createStatement(); \t \t \t \t statement.setQueryTimeout (30); – joesid