Created
July 7, 2011 07:19
-
-
Save eirikbakke/1069036 to your computer and use it in GitHub Desktop.
The VideoDatabase Class
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
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.util.List; | |
public class VideoDatabase { | |
public static List<Video> loadVideos() throws SQLException { | |
throw new UnsupportedOperationException("TODO: Implement when instructed."); | |
} | |
public static void insertVideo(Video v) throws SQLException { | |
throw new UnsupportedOperationException("TODO: Implement when instructed."); | |
} | |
public static void deleteVideo(Video v) throws SQLException { | |
throw new UnsupportedOperationException("TODO: Implement when instructed."); | |
} | |
public static void updateVideo(Video v) throws SQLException { | |
throw new UnsupportedOperationException("TODO: Implement when instructed."); | |
} | |
public static void dropAndCreateTables() throws SQLException { | |
boolean useMySQL = DatabaseConnector.getInstance().isMySQL(); | |
Statement s = DatabaseConnector.getInstance().getConnection().createStatement(); | |
// Work around some DDL syntax differences between MySQL and SQLite. | |
String engine = useMySQL ? "ENGINE=InnoDB" : ""; | |
String autoinc = useMySQL ? "AUTO_INCREMENT" : "AUTOINCREMENT"; | |
try { | |
// TODO: Add your tables below (one example is shown below). | |
s.execute("DROP TABLE IF EXISTS sometable;"); | |
s.execute( | |
"CREATE TABLE sometable (" | |
+ " someIntegerID INTEGER PRIMARY KEY " + autoinc + "," | |
+ " someBigString VARCHAR(255) NOT NULL," | |
+ " someConstantLengthString CHAR(10) NOT NULL," | |
+ " someInteger INTEGER NOT NULL" | |
+ ") " + engine + ";" | |
); | |
} finally { | |
s.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment