Started implementing basic database functions.
This commit is contained in:
@@ -2,8 +2,11 @@ package de.katho.kBorrow.db;
|
|||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class sqliteConnector
|
* @class sqliteConnector
|
||||||
@@ -27,14 +30,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
System.out.println(this.dbHandle);
|
System.out.println(this.dbHandle);
|
||||||
this.connection = DriverManager.getConnection("jdbc:sqlite:"+this.dbHandle);
|
this.connection = DriverManager.getConnection("jdbc:sqlite:"+this.dbHandle);
|
||||||
|
|
||||||
/*String query = "create table test "
|
System.out.println(this.isConfigured());
|
||||||
+ "(ID INT PRIMARY KEY NOT NULL,"
|
|
||||||
+ "NAME TEXT NOT NULL)";
|
|
||||||
|
|
||||||
Statement stm = this.connection.createStatement();
|
|
||||||
stm.executeUpdate(query);
|
|
||||||
stm.close();
|
|
||||||
this.connection.close();*/
|
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e){
|
catch (ClassNotFoundException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -44,4 +40,20 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isConfigured(){
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "SELECT value FROM kborrow WHERE setting_name='is_configured' LIMIT 1";
|
||||||
|
|
||||||
|
ResultSet rs = st.executeQuery(query);
|
||||||
|
|
||||||
|
return rs.getBoolean("value");
|
||||||
|
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
CREATE TABLE kborrow (
|
||||||
|
setting_name TEXT,
|
||||||
|
value INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE article (
|
CREATE TABLE article (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
@@ -28,3 +33,9 @@ CREATE TABLE lending (
|
|||||||
end_date DATE,
|
end_date DATE,
|
||||||
comment
|
comment
|
||||||
);
|
);
|
||||||
|
|
||||||
|
insert into kborrow
|
||||||
|
(setting_name, value)
|
||||||
|
VALUES
|
||||||
|
('is_configured', 1)
|
||||||
|
;
|
||||||
Reference in New Issue
Block a user