Solved mySQL being strange

Discussion in 'Plugin Development' started by lewysryan, Dec 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    lewysryan

    Okay so im making a mySQL punishment system but for some reason im getting this error in which I just don't understand.

    Code:
    19.12 09:52:55 [Server] WARN at dexoria.core.sqlDatabases.PunishmentSystem.getAllPunishmentsFromUUID(PunishmentSystem.java:190)
    19.12 09:52:55 [Server] WARN at dexoria.core.sqlDatabases.PunishmentSystem.getPunishment(PunishmentSystem.java:115)
    19.12 09:52:55 [Server] WARN at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2677)
    19.12 09:52:55 [Server] WARN at com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:818)
    19.12 09:52:55 [Server] WARN at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    19.12 09:52:55 [Server] WARN at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    19.12 09:52:55 [Server] WARN at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    19.12 09:52:55 [Server] WARN at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    19.12 09:52:55 [Server] WARN java.sql.SQLException: Column Index out of range, 19 > 12. 
    I know what it is saying im trying to get column 19 when it only goes up to 12 but I can't figure out why it's trying to get column 19.

    CODE:

    Code:
     public PastPunishment getPunishment(int ID)
          {
            try {
                 ResultSet res =  DexCore.getSQLStaticly().querySQL("SELECT * FROM Punishment WHERE ID = '" + ID + "';");
                 res.next();
              @SuppressWarnings("deprecation")
            Player player = Bukkit.getPlayer(res.getString("PlayerName"));
              int pType = res.getInt("pType");
             
              PunishmentType type = null;
              switch(pType){
              case 1: type = PunishmentType.CHAT;
                  break;
              case 2: type = PunishmentType.GAMEPLAY;
                  break;
              case 3: type = PunishmentType.HACKING;
                  break;
              }
             
              String staff = res.getString("StaffName");
              String reason = res.getString("reason");
              String remove = res.getString("RemoveReason");
              String removedby = res.getString("RemovedReason");
             
              boolean activate;
              this.isActive(ID);
              if(res.getInt("Active") == 1)
                  activate = true;
              else{
                  activate = false;
              }
             
              int sev = res.getInt("Sev");
             
              PunishmentSev severity = null;
             
              switch(sev){
              case 1: severity = PunishmentSev.SEV_1;
                  break;
              case 2: severity = PunishmentSev.SEV_2;
                  break;
              case 3: severity = PunishmentSev.SEV_3;
                  break;
              case 4: severity = PunishmentSev.SEV_4;
                  break;
              default: severity = PunishmentSev.SEV_1;
                  break;
              }
              Timestamp start = res.getTimestamp("Activated");
             
              Timestamp end = res.getTimestamp("Ends");
             
              PastPunishment p = new PastPunishment(ID, player,
                      type, reason, staff,
                              remove, removedby ,activate, start, end, severity);
              return p;
            }
            catch (SQLException|ClassNotFoundException e) {
              e.printStackTrace();
            }
            return null;
          }
    mySQL table:
    [​IMG]
     
  2. Offline

    Lolmewn

    Isn't it "Reason", not "reason"?
    Hence the reason I lowercase column names :p

    PS: Might as well use the UUID instead of the player name to identify the player ;)
     
    lewysryan likes this.
  3. Offline

    lewysryan

    I do use the UUID but store the player name just so I can get all the info I need to display the punishment. Also I got it working. It was exactly what you said :D Thanks man, gotta stop rushing things lol
     
Thread Status:
Not open for further replies.

Share This Page