· 8 years ago · Feb 19, 2018, 10:28 AM
1import java.sql.SQLException;
2import java.sql.Statement;
3import java.util.List;
4
5public class VideoDatabase {
6 public static List<Video> loadVideos() throws SQLException {
7 throw new UnsupportedOperationException("TODO: Implement when instructed.");
8 }
9
10 public static void insertVideo(Video v) throws SQLException {
11 throw new UnsupportedOperationException("TODO: Implement when instructed.");
12 }
13
14 public static void deleteVideo(Video v) throws SQLException {
15 throw new UnsupportedOperationException("TODO: Implement when instructed.");
16 }
17
18 public static void updateVideo(Video v) throws SQLException {
19 throw new UnsupportedOperationException("TODO: Implement when instructed.");
20 }
21
22 public static void dropAndCreateTables() throws SQLException {
23 boolean useMySQL = DatabaseConnector.getInstance().isMySQL();
24 Statement s = DatabaseConnector.getInstance().getConnection().createStatement();
25 // Work around some DDL syntax differences between MySQL and SQLite.
26 String engine = useMySQL ? "ENGINE=InnoDB" : "";
27 String autoinc = useMySQL ? "AUTO_INCREMENT" : "AUTOINCREMENT";
28 try {
29 // TODO: Add your tables below (one example is shown below).
30
31 s.execute("DROP TABLE IF EXISTS sometable;");
32
33 s.execute(
34 "CREATE TABLE sometable ("
35 + " someIntegerID INTEGER PRIMARY KEY " + autoinc + ","
36 + " someBigString VARCHAR(255) NOT NULL,"
37 + " someConstantLengthString CHAR(10) NOT NULL,"
38 + " someInteger INTEGER NOT NULL"
39 + ") " + engine + ";"
40 );
41 } finally {
42 s.close();
43 }
44 }
45}