db setup
This commit is contained in:
		
							
								
								
									
										8
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								pom.xml
									
									
									
									
									
								
							@@ -38,6 +38,14 @@
 | 
				
			|||||||
            <version>${junit.version}</version>
 | 
					            <version>${junit.version}</version>
 | 
				
			||||||
            <scope>test</scope>
 | 
					            <scope>test</scope>
 | 
				
			||||||
        </dependency>
 | 
					        </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>
 | 
					    </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <build>
 | 
					    <build>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,8 +6,10 @@ import javafx.scene.Scene;
 | 
				
			|||||||
import javafx.stage.Stage;
 | 
					import javafx.stage.Stage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.sql.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class HelloApplication extends Application {
 | 
					public class HelloApplication extends Application {
 | 
				
			||||||
 | 
					    private static final String dbLocation = "jdbc:sqlite:"+HelloApplication.class.getResource("database/database.db");
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void start(Stage stage) throws IOException {
 | 
					    public void start(Stage stage) throws IOException {
 | 
				
			||||||
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
 | 
					        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) {
 | 
					    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();
 | 
					        launch();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static Connection connect(){
 | 
				
			||||||
 | 
					        Connection conn = null;
 | 
				
			||||||
 | 
					        try{
 | 
				
			||||||
 | 
					            conn = DriverManager.getConnection(dbLocation);
 | 
				
			||||||
 | 
					        }catch (SQLException e){
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return conn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
module com.bib.essensbestellungsverwaltung {
 | 
					module com.bib.essensbestellungsverwaltung {
 | 
				
			||||||
    requires javafx.controls;
 | 
					    requires javafx.controls;
 | 
				
			||||||
    requires javafx.fxml;
 | 
					    requires javafx.fxml;
 | 
				
			||||||
 | 
					    requires java.sql;
 | 
				
			||||||
 | 
					    requires org.xerial.sqlitejdbc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    opens com.bib.essensbestellungsverwaltung to javafx.fxml;
 | 
					    opens com.bib.essensbestellungsverwaltung to javafx.fxml;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user