Skip to content

Instantly share code, notes, and snippets.

@eirikbakke
Created July 7, 2011 07:19
Show Gist options
  • Save eirikbakke/1069036 to your computer and use it in GitHub Desktop.
Save eirikbakke/1069036 to your computer and use it in GitHub Desktop.
The VideoDatabase Class
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