Skip to content

Commit

Permalink
db setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 25, 2024
1 parent b925165 commit fe8f705
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
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();
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 fe8f705

Please sign in to comment.