0
내가 만든 응용 프로그램을 통해 풀링 된 데이터 소스 (msaccess 데이터베이스)를 사용하여 로컬 데이터베이스 (h2 데이터베이스를 사용하는 클라이언트 측)를 업데이트하고 있습니다. 내가 가진 문제는 요청을 제출할 때 "INSERT INTO USERS (NAME, CODE) VALUES (Me, hfd5255fd4
);" 응용 프로그램이 완벽하게 실행되고 아무 것도 오류 로그에보고되지만 데이터베이스에서 변경된 사항은 없습니다. c3p0 CombopooledDataSource가 SQL 업데이트를 수행하지 않음
private static Connection getDatabase() throws Exception {
cpds.setDriverClass("net.ucanaccess.jdbc.UcanaccessDriver");
// loads the jdbc driver
cpds.setJdbcUrl("jdbc:ucanaccess://"
+ (new File("Ressources/filter.mdb").getAbsolutePath()));
cpds.setUser("admin");
cpds.setPassword("ibnsina");
cpds.setAutoCommitOnClose(false);
return cpds.getConnection(); //tried removing this , but no effect
}
----doing some other stuff---
private static updating() throws exception{
conn = getDatabase();
File fileUpload = new File(logPath + "UploadLog.txt");
BufferedReader readerUpload = new BufferedReader(new FileReader(
fileUpload));
String Uploadingline = "";
StringBuffer secondaryline = new StringBuffer();
if (readerUpload.ready()) {
System.out.println("Uploadtxt ready");
Statement stUpload = conn.createStatement();
System.out.println("Stupload ready");
while ((Uploadingline = readerUpload.readLine()) != null) {
if (Uploadingline.endsWith(";")) {
secondaryline.append(Uploadingline);
/*stUpload.executeUpdate(secondaryline.toString()); tried this to execute each line separatly*/
stUpload.addBatch(secondaryline.toString());
System.out.println("Reading line :" + secondaryline);
secondaryline.setLength(0);
} else {
secondaryline.append(Uploadingline);
}
}
stUpload.executeBatch();
stUpload.clearBatch();
conn.commit(); //i even tried adding this to make it commit even tho autocommit is by default ON
stUpload.close();}
이 무엇인지 포스터 이벤트보다 훨씬 더 많이. 사소한 단점 : 마지막으로 호출 된 releaseConnection() 메소드에는 conn.commit()이 포함되어서는 안됩니다. 그것은 두 가지 이유 때문에 중요합니다 : 1) 당신이 update()를 호출하는 메소드의 본문에서 Exception이 발생하면, 작업은 부분적으로 만 수행되고, commit (commit 절에서)를 호출하기보다는 rollback()(); 2) conn.commit() 중에 Exception이 발생하면 conn.close()에 대한 호출이 건너 뜁니다. 이로 인해 Connections가 풀로 반환되지 않을 수 있습니다. –
트랜잭션 동작을 원할 경우 try 블록 맨 위에서 conn.setAutoCommit (false)를 호출하고 작업 한 다음 try 블록의 맨 아래에있는 conn.commit()을 호출하십시오. conn.rollback()을 catch 절에 넣고 conn.close()를 마지막에 넣습니다. –
'throws Exception'을 추가 한 후에'return cpds' 유형이 Datasource 대신 ComboPooledDatasource가되어서는 안됩니까 ?? 컴파일 오류가 발생합니다. @ Steve Waldman : 일방적 인 트랜잭션이기 때문에 conn.rollback()이 필요하지 않지만 나중에 포함하고 싶다면 rollback()을 호출하면 이전에 수행 된 모든 변경 사항이 취소되지 않습니다. stUpload.executebatch()가 호출 되었습니까? –