Compare commits
No commits in common. "37a41331c1b8e9268ac682e4b034c17cc4f50aeb" and "da20ce1a80a6f0d053dc4d199249cc58d97c094e" have entirely different histories.
37a41331c1
...
da20ce1a80
3 changed files with 33 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,7 +5,6 @@ tomcat.5000
|
||||||
# Gradle generated files
|
# Gradle generated files
|
||||||
.gradle
|
.gradle
|
||||||
app/build
|
app/build
|
||||||
.settings
|
|
||||||
|
|
||||||
# IntelliJ Idea project files
|
# IntelliJ Idea project files
|
||||||
.idea
|
.idea
|
||||||
|
|
13
app/.settings/org.eclipse.jdt.core.prefs
Normal file
13
app/.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#
|
||||||
|
#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
|
|
@ -6,16 +6,29 @@ import java.sql.*;
|
||||||
*/
|
*/
|
||||||
public class Database implements AutoCloseable {
|
public class Database implements AutoCloseable {
|
||||||
|
|
||||||
// The connection to the database
|
// 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
|
||||||
private Connection conn = null;
|
private Connection conn = null;
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
// Connect to sqlite
|
|
||||||
try{
|
try{
|
||||||
Class.forName("org.sqlite.JDBC");
|
conn = DriverManager.getConnection("jdbc:mysql://" + databaseServerAddress + "/" +
|
||||||
conn = DriverManager.getConnection("jdbc:sqlite:database.db");
|
database, databaseUser, databasePassword);
|
||||||
System.out.println("Opened database successfully");
|
|
||||||
} catch (Exception e) {
|
// 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) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue