Sqlite instead of mysql for local use
This commit is contained in:
parent
7a3ff989fb
commit
37a41331c1
1 changed files with 7 additions and 20 deletions
|
@ -6,29 +6,16 @@ import java.sql.*;
|
||||||
*/
|
*/
|
||||||
public class Database implements AutoCloseable {
|
public class Database implements AutoCloseable {
|
||||||
|
|
||||||
// If you have the mysql server on your own computer use "localhost" as server address.
|
// The connection to the database
|
||||||
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() {
|
||||||
try{
|
// Connect to sqlite
|
||||||
conn = DriverManager.getConnection("jdbc:mysql://" + databaseServerAddress + "/" +
|
try {
|
||||||
database, databaseUser, databasePassword);
|
Class.forName("org.sqlite.JDBC");
|
||||||
|
conn = DriverManager.getConnection("jdbc:sqlite:database.db");
|
||||||
// Display the contents of the database in the console.
|
System.out.println("Opened database successfully");
|
||||||
// This should be removed in the final version
|
} catch (Exception e) {
|
||||||
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