Skip to content

Commit

Permalink
removed setup code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 28, 2024
1 parent 3d58959 commit 7b7a17c
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,16 @@
import Util.ConnectionUtil;
import Controller.SocialMediaController;
import io.javalin.Javalin;

import Util.ConnectionUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
// import java.util.Scanner;

/**
* This class is provided with a main method to allow you to manually run and test your application. This class will not
* affect your program in any way and you may write whatever code you like here.
*/
public class Main {
public static void main(String[] args) {
databaseSetup();
ConnectionUtil.resetTestDatabase();
SocialMediaController controller = new SocialMediaController();
Javalin app = controller.startAPI();
app.start(8080);
}

public static void databaseSetup(){
try {
Connection conn = ConnectionUtil.getConnection();
String createAccountTable = "CREATE TABLE Account ("
+ "account_id INTEGER PRIMARY KEY AUTO_INCREMENT"
+ "username VARCHAR(255) UNIQUE,"
+ "password VARCHAR(255)";
PreparedStatement ps1 = conn.prepareStatement(createAccountTable);
ps1.executeUpdate();

String createMessageTable = "CREATE TABLE Message ("
+ "message_id INTEGER PRIMARY KEY AUTO_INCREMENT,"
+ "posted_by INTEGER,"
+ "message_text VARCHAR(255),"
+ "time_posted_epoch LONG,"
+ "FOREIGN KEY (posted_by) REFERENCES Account(account_id)"
+ ")";
PreparedStatement ps2 = conn.prepareStatement(createMessageTable);
ps2.executeUpdate();
}catch(SQLException e){
e.printStackTrace();
}
}
}

0 comments on commit 7b7a17c

Please sign in to comment.