Lisätty laskutustieto tietokantaan
Signed-off-by: laurimaaninka <lauri.maaninka@gmail.com>
This commit is contained in:
Generated
+1
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="SqlDialectMappings">
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources/fi/lpam/tietokanta.sql" dialect="SQLite" />
|
||||||
<file url="PROJECT" dialect="SQLite" />
|
<file url="PROJECT" dialect="SQLite" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
package fi.lpam.dataluokat;
|
package fi.lpam.dataluokat;
|
||||||
|
|
||||||
import fi.lpam.gui.virheDialogit.SiirtoVirhe;
|
import fi.lpam.gui.virheDialogit.SiirtoVirhe;
|
||||||
import fi.lpam.gui.virheDialogit.YhteysVirhe;
|
|
||||||
|
|
||||||
import fi.lpam.Main;
|
import fi.lpam.Main;
|
||||||
import javafx.scene.control.Alert;
|
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -15,16 +13,14 @@ public class Tietokanta {
|
|||||||
private static String osoite;
|
private static String osoite;
|
||||||
private static String dbPath = SystemUtils.getUserHome().getAbsolutePath() + "\\OneDrive\\Kuljetusruokasovellus\\tietokanta.db";
|
private static String dbPath = SystemUtils.getUserHome().getAbsolutePath() + "\\OneDrive\\Kuljetusruokasovellus\\tietokanta.db";
|
||||||
|
|
||||||
public Tietokanta(boolean dev) throws IOException {
|
public Tietokanta(boolean dev) {
|
||||||
if (dev) dbPath = "testikanta.db";
|
if (dev) dbPath = "testikanta.db";
|
||||||
File file = new File(dbPath);
|
File file = new File(dbPath);
|
||||||
try {
|
try {
|
||||||
//noinspection ResultOfMethodCallIgnored
|
boolean _ = file.getParentFile().mkdirs();
|
||||||
file.getParentFile().mkdirs();
|
boolean _ = file.createNewFile();
|
||||||
}
|
}
|
||||||
catch (Exception _) {}
|
catch (Exception _) {}
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
file.createNewFile();
|
|
||||||
|
|
||||||
osoite = "jdbc:sqlite:" + file.getAbsolutePath();
|
osoite = "jdbc:sqlite:" + file.getAbsolutePath();
|
||||||
|
|
||||||
@@ -37,24 +33,35 @@ public class Tietokanta {
|
|||||||
for (String query : sql.split(";")) {
|
for (String query : sql.split(";")) {
|
||||||
conn.createStatement().execute(query);
|
conn.createStatement().execute(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (SQLException | IOException e) {
|
||||||
SiirtoVirhe virhe = new SiirtoVirhe(e);
|
handleException(e);
|
||||||
virhe.showAndWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Lisää laskutustietokenttä Asiakkaat tauluun
|
||||||
|
try (Connection conn = haeYhteys()) {
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("alter table asiakkaat add column laskutustieto TEXT");
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
if (!e.getMessage().contains("duplicate column name: laskutustieto")) {
|
||||||
|
handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Connection haeYhteys() {
|
public static Connection haeYhteys() {
|
||||||
|
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
try {
|
try {
|
||||||
connection = DriverManager.getConnection(osoite);
|
connection = DriverManager.getConnection(osoite);
|
||||||
} catch (Exception e) {
|
} catch (SQLException e) {
|
||||||
Alert virhe = new YhteysVirhe(e);
|
handleException(e);
|
||||||
virhe.showAndWait();
|
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleException(Exception e) {
|
||||||
|
SiirtoVirhe virhe = new SiirtoVirhe(e);
|
||||||
|
virhe.showAndWait();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user