PulsCOunterDatabase

WIP-PC2
Harald Wolff 2016-09-20 09:22:29 +02:00
parent 4a1bdab688
commit 88c7073dcb
1 changed files with 31 additions and 2 deletions

View File

@ -1,5 +1,9 @@
package org.hwo.pulscounter.db;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@ -24,14 +28,39 @@ public class PulsCounterDatabase {
getClass().getClassLoader().loadClass("org.hsqldb.jdbcDriver");
dbConnection = DriverManager.getConnection("jdbc:hsqldb:file:synololog-hsql", "SA", "");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
log(ERROR,"HyperSQL Driver could not be loaded. [%s]",e.toString());
}
InputStream is = getClass().getResourceAsStream("/org/hwo/pulscounter/db/schema/schema.sql");
if (is == null){
log(ERROR,"Database schema file not found");
} else {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
do {
String sql = br.readLine();
if (sql == null){
break;
}
sql = sql.trim();
if (!sql.equals("") && !sql.startsWith("//")){
log(sql);
executeSimpleSQL(sql);
}
}while (true);
} catch (IOException e) {
log(e);
}
}
}
public void close(){