Compare commits

...

2 commits

Author SHA1 Message Date
Imbus
37a41331c1 Sqlite instead of mysql for local use 2024-02-08 14:50:12 +01:00
Imbus
7a3ff989fb more ignore 2024-02-08 14:49:47 +01:00
3 changed files with 8 additions and 33 deletions

1
.gitignore vendored
View file

@ -5,6 +5,7 @@ tomcat.5000
# Gradle generated files
.gradle
app/build
.settings
# IntelliJ Idea project files
.idea

View file

@ -1,13 +0,0 @@
#
#Thu Feb 08 14:14:29 CET 2024
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.source=21
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.debug.sourceFile=generate

View file

@ -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 = "<your databse user on vm26>"; // database login user
private static String databasePassword = "<your password>"; // database login password
private static String database = "<your database, normally the same as database user>"; // 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);
}
}