Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package co.windall.twitter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- * The Class Database.
- * Provides a connection to the SQLite database.
- */
- public class Database {
- /** The jdbc sqlite connection. */
- private Connection connection;
- /**
- * Instantiates a new database object.
- */
- public Database() {
- super();
- try {
- //Connect to the database
- Class.forName("org.sqlite.JDBC");
- this.connection = DriverManager.getConnection("jdbc:sqlite:bot2.db");
- //If this is a first time use or the database has been reset, make the need tables
- Statement stmt = connection.createStatement();
- String sql = "CREATE TABLE IF NOT EXISTS User ("
- + "id INT PRIMARY KEY," //Twitter ID
- + "followedMe INT," //TIME
- + "followedThem INT," //TIME
- + "unfollowedMe INT," //TIME
- + "unfollowedThem INT," //TIME
- + "status INT)"; //0=DEFAULT,1=PROTECTED,2=VIT,3=CHURN,4=CULL,5=FOLLOW,6=OUTSIDER,7=DEAD
- stmt.executeUpdate(sql);
- stmt.close();
- } catch (Exception e) {
- System.err.println(e.getClass().getName() + ": " + e.getMessage());
- System.exit(0);
- }
- }
- /**
- * Gets the database connection.
- *
- * @return the connection
- */
- public Connection getConnection() {
- return connection;
- }
- /**
- * Closes the database connection.
- */
- public void close() {
- try {
- this.connection.close();
- } catch (SQLException e) {
- System.err.println(e.getClass().getName() + ": " + e.getMessage());
- }
- }
- /* (non-Javadoc)
- * @see java.lang.Object#finalize()
- * Adds a call to the close method
- */
- @Override
- protected void finalize() throws Throwable {
- this.close();
- super.finalize();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement