Example #1
0
  @Override
  public void run() {
    String statement = "SELECT * FROM " + table + " WHERE name='" + syncingName + "'";
    ResultSet rs = sql.executeQuery(statement);
    if (rs != null) {

      try {
        if (rs.getDate("modified") == null
            || rs.getDate("modified").before(Calendar.getInstance().getTime())) {
          // database is out of date
          setDBTime();
        } else {
          // database is more recent
          data.set(syncingName, getDBTime(rs));
        }
      } catch (SQLException e) {
        System.out.println("Playtimes.run");
        System.out.println("SQLException: " + e.getMessage());
        System.out.println("SQLState: " + e.getSQLState());
        System.out.println("VendorError: " + e.getErrorCode());
      }
    } else {
      // non existing entry
      setDBTime();
    }
  }
Example #2
0
 private void setupTable() {
   String statement =
       "CREATE TABLE  IF NOT EXISTS "
           + table
           + " "
           + "(name VARCHAR(16) not NULL, "
           + " time INTEGER not NULL, "
           + " modified TIMESTAMP not NULL, "
           + " PRIMARY KEY ( name ))";
   sql.execute(statement);
 }
Example #3
0
 private void setDBTime() {
   String statement =
       "INSERT INTO "
           + table
           + " VALUES ('"
           + syncingName
           + "', "
           + syncingTime
           + ", CURRENT_TIMESTAMP) "
           + "ON DUPLICATE KEY UPDATE "
           + "time="
           + syncingTime;
   sql.execute(statement);
 }
Example #4
0
  private void sqlSetup(SimpleYamlConfiguration config) {
    ConfigurationSection s = config.getConfigurationSection("sql");

    Boolean enabled = s.getBoolean("enabled");
    if (enabled != null && enabled) {

      String hostname = s.getString("hostname");
      String username = s.getString("username");
      String password = s.getString("password");
      String database = s.getString("database");
      this.table = s.getString("table");

      this.sql = new SQLDataStorage(hostname, username, password, database);
      if (!sql.connect()) {
        this.sql = null;
        plugin.getLogger().severe("Could not connect to " + hostname);
      } else {
        plugin.getLogger().info("Successfully established connection to " + hostname);
      }
    }
  }