From 37a41331c1b8e9268ac682e4b034c17cc4f50aeb Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Thu, 8 Feb 2024 14:50:12 +0100 Subject: [PATCH] Sqlite instead of mysql for local use --- app/src/main/java/servlet/Database.java | 27 +++++++------------------ 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/servlet/Database.java b/app/src/main/java/servlet/Database.java index eb89056..e9a3283 100644 --- a/app/src/main/java/servlet/Database.java +++ b/app/src/main/java/servlet/Database.java @@ -6,29 +6,16 @@ import java.sql.*; */ public class Database implements AutoCloseable { - // If you have the mysql server on your own computer use "localhost" as server address. - private static String databaseServerAddress = "vm26.cs.lth.se"; - private static String databaseUser = ""; // database login user - private static String databasePassword = ""; // database login password - private static String database = ""; // the database to use, i.e. default schema + // The connection to the database private Connection conn = null; public Database() { - try{ - conn = DriverManager.getConnection("jdbc:mysql://" + databaseServerAddress + "/" + - database, databaseUser, databasePassword); - - // Display the contents of the database in the console. - // This should be removed in the final version - try(Statement stmt = conn.createStatement()) { - ResultSet rs = stmt.executeQuery("select * from Respondents"); - while (rs.next()) { - String name = rs.getString("name"); - System.out.println(name); - } - } - - } catch (SQLException e) { + // Connect to sqlite + try { + Class.forName("org.sqlite.JDBC"); + conn = DriverManager.getConnection("jdbc:sqlite:database.db"); + System.out.println("Opened database successfully"); + } catch (Exception e) { throw new RuntimeException(e); } }