Advertisement
Guest User

Untitled

a guest
Aug 30th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.47 KB | None | 0 0
  1. package com.foxtrot.utils.tools;
  2.  
  3. import java.io.IOException;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.SQLException;
  8.  
  9. import com.foxtrot.cache.Cache;
  10. import com.foxtrot.utils.Utils;
  11. import com.foxtrot.utils.tools.ItemBonuses;
  12.  
  13.  
  14. /**
  15.  * @author Frosty Teh Snowman
  16.  *
  17.  *         Unpacks the Item Bonuses that are packed into the bonuses.ib file.
  18.  */
  19. public class ItemBonusesLoader {
  20.  
  21.     public static final void main(String[] args) {
  22.         System.out.println("Loader Started.");
  23.         try {
  24.             Cache.init();
  25.             System.out.println("Cache Initiated.");
  26.         } catch (IOException e) {
  27.             System.out.println("Exception in initializing cache.");
  28.         }
  29.         ItemBonuses.init();
  30.         System.out.println("Item Bonuses Initiated.");
  31.  
  32.         try {
  33.             try (Connection conn = DriverManager.getConnection("jdbc:mysql://Localhost:3306/Q718?useServerPrepStmts=false&rewriteBatchedStatements=true", "root", "")) {
  34.                 try (PreparedStatement preparedStmt = conn.prepareStatement("INSERT INTO item_bonuses (itemId, Astab, Aslash, Acrush, Amagic, Arange, Dstab, Dslash, Dcrush, Dmagic, Drange, Dsummoning, AbsorbMelee, AbsorbMagic, AbsorbRange, Strength, RStrength, PRayer, MagicDamage)" +
  35.                     "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
  36.  
  37.                     for (int itemId = 0; itemId < Utils.getItemDefinitionsSize(); itemId++)
  38.            //       int itemId = 6585; //testing loading single item
  39.                     {
  40.                         System.out.println("Getting Values for item " + itemId);
  41.                         int[] bonuses = ItemBonuses.getItemBonuses(itemId);
  42.                         preparedStmt.setInt(1, itemId);
  43.                         preparedStmt.setInt(2, bonuses[0]);
  44.                         preparedStmt.setInt(3, bonuses[1]);
  45.                         preparedStmt.setInt(4, bonuses[2]);
  46.                         preparedStmt.setInt(5, bonuses[3]);
  47.                         preparedStmt.setInt(6, bonuses[4]);
  48.                         preparedStmt.setInt(7, bonuses[5]);
  49.                         preparedStmt.setInt(8, bonuses[6]);
  50.                         preparedStmt.setInt(9, bonuses[7]);
  51.                         preparedStmt.setInt(10, bonuses[8]);
  52.                         preparedStmt.setInt(11, bonuses[9]);
  53.                         preparedStmt.setInt(12, bonuses[10]);
  54.                         preparedStmt.setInt(13, bonuses[11]);
  55.                         preparedStmt.setInt(14, bonuses[12]);
  56.                         preparedStmt.setInt(15, bonuses[13]);
  57.                         preparedStmt.setInt(16, bonuses[14]);
  58.                         preparedStmt.setInt(17, bonuses[15]);
  59.                         preparedStmt.setInt(18, bonuses[16]);
  60.                         preparedStmt.setInt(19, bonuses[17]);
  61.                         preparedStmt.addBatch();
  62.                     }
  63.  
  64.                     System.out.println("executing query");
  65.                     preparedStmt.executeBatch();
  66.                     System.out.println("finished unpacking");
  67.                 }
  68.             }
  69.         }              
  70.         catch (NullPointerException npe) {
  71.             System.err.println("Got an exception!");
  72.             System.err.println(npe.getMessage());
  73.         }catch (SQLException e)
  74.         {
  75.               System.err.println("Got an exception!");
  76.               System.err.println(e.getMessage());
  77.             }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement