generated from revature-curriculum/pep-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
2 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |