PulsCOunterDatabase
parent
4a1bdab688
commit
88c7073dcb
|
@ -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(){
|
||||
|
|
Loading…
Reference in New Issue