Versio 1, ensimmäinen committi!

This commit is contained in:
2026-04-08 19:34:00 +03:00
commit 2d4000f6cd
43 changed files with 2699 additions and 0 deletions
@@ -0,0 +1,60 @@
package fi.lpam.dataluokat;
import fi.lpam.gui.virheDialogit.SiirtoVirhe;
import fi.lpam.gui.virheDialogit.YhteysVirhe;
import fi.lpam.Main;
import javafx.scene.control.Alert;
import org.apache.commons.lang3.SystemUtils;
import java.io.*;
import java.sql.*;
import java.util.Objects;
public class Tietokanta {
private static String osoite;
private static String dbPath = SystemUtils.getUserHome().getAbsolutePath() + "\\OneDrive\\Kuljetusruokasovellus\\tietokanta.db";
public Tietokanta(boolean dev) throws IOException {
if (dev) dbPath = "tietokanta.db";
File file = new File(dbPath);
try {
//noinspection ResultOfMethodCallIgnored
file.getParentFile().mkdirs();
}
catch (Exception _) {}
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
osoite = "jdbc:sqlite:" + file.getAbsolutePath();
try (Connection conn = haeYhteys()) {
InputStream is = Objects.requireNonNull(Main.class.getResourceAsStream("tietokanta.sql"));
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String sql = br.readAllAsString();
for (String query : sql.split(";")) {
conn.createStatement().execute(query);
}
}
catch (Exception e) {
SiirtoVirhe virhe = new SiirtoVirhe(e);
virhe.showAndWait();
}
}
public static Connection haeYhteys() {
Connection connection = null;
try {
connection = DriverManager.getConnection(osoite);
} catch (Exception e) {
Alert virhe = new YhteysVirhe(e);
virhe.showAndWait();
}
return connection;
}
}