diff --git a/pom.xml b/pom.xml index df0870d..8da2cd8 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,14 @@ ${junit.version} test + + + + org.xerial + sqlite-jdbc + 3.40.0.0 + + diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/HelloApplication.java b/src/main/java/com/bib/essensbestellungsverwaltung/HelloApplication.java index b0976fb..54876fd 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/HelloApplication.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/HelloApplication.java @@ -6,8 +6,10 @@ import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; +import java.sql.*; public class HelloApplication extends Application { + private static final String dbLocation = "jdbc:sqlite:"+HelloApplication.class.getResource("database/database.db"); @Override public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); @@ -18,6 +20,36 @@ public class HelloApplication extends Application { } public static void main(String[] args) { + String sql = """ + CREATE TABLE IF NOT EXISTS user ( + id integer PRIMARY KEY, + name text);"""; + String sql2 = "SELECT * FROM user WHERE id > ?"; + String sql3 = "INSERT INTO user (id,name) VALUES (1,'test1')"; + try(Connection conn = connect(); + Statement stmt = conn.createStatement()){ + //stmt.execute(sql); + //stmt.execute(sql3); + PreparedStatement pstmt = conn.prepareStatement(sql2); + pstmt.setInt(1,1); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()){ + System.out.println(rs.getInt("id")); + } + }catch (SQLException e){ + e.printStackTrace(); + return; + } launch(); } + + private static Connection connect(){ + Connection conn = null; + try{ + conn = DriverManager.getConnection(dbLocation); + }catch (SQLException e){ + e.printStackTrace(); + } + return conn; + } } \ No newline at end of file diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 3338433..79a355a 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,6 +1,8 @@ module com.bib.essensbestellungsverwaltung { requires javafx.controls; requires javafx.fxml; + requires java.sql; + requires org.xerial.sqlitejdbc; opens com.bib.essensbestellungsverwaltung to javafx.fxml; diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/database/database.db b/src/main/resources/com/bib/essensbestellungsverwaltung/database/database.db new file mode 100644 index 0000000..e69de29