This commit is contained in:
Malte Schulze Hobeling 2022-11-29 22:35:12 +01:00
parent efd2657ef4
commit d5d98fde7a
4 changed files with 42 additions and 0 deletions

View File

@ -38,6 +38,14 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.40.0.0</version>
</dependency>
</dependencies>
<build>

View File

@ -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;
}
}

View File

@ -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;