Code:
package com.foxtrot.utils.tools;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import com.foxtrot.cache.Cache;
import com.foxtrot.utils.tools.ItemBonuses;
import com.foxtrot.utils.Logger;
import com.foxtrot.utils.Utils;
/**
* @author Frosty Teh Snowman
*
* Unpacks the Item Bonuses that are packed into the bonuses.ib file.
*/
public class ItemBonusesUnpacker {
public static final void main(String[] args) {
log("Unpacker Started.");
try {
Cache.init();
log("Cache Initiated.");
} catch (IOException e) {
log("Exception in initializing cache.");
}
ItemBonuses.init();
log("Item Bonuses Initiated.");
for (int itemId = 0; itemId < Utils.getItemDefinitionsSize(); itemId++) {
log("Getting Values for item " + itemId);
int[] bonuses = ItemBonuses.getItemBonuses(itemId);
try
{
String myDriver = "org.gjt.mm.mysql.Driver";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection("jdbc:mysql://Localhost:3306/Q718", "root", "");
String query = "INSERT INTO item_bonuses (itemId, Astab, Aslash, Acrush, Amagic, Arange, Dstab, Dslash, Dcrush, Dmagic, Drange, Dsummoning, AbsorbMelee, AbsorbMagic, AbsorbRange, Strength, RStrength, PRayer, MagicDamage)" +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setInt (1, itemId);
preparedStmt.setInt (2, bonuses[0]);
preparedStmt.setInt (3, bonuses[1]);
preparedStmt.setInt (4, bonuses[2]);
preparedStmt.setInt (5, bonuses[3]);
preparedStmt.setInt (6, bonuses[4]);
preparedStmt.setInt (7, bonuses[5]);
preparedStmt.setInt (8, bonuses[6]);
preparedStmt.setInt (9, bonuses[7]);
preparedStmt.setInt (10, bonuses[8]);
preparedStmt.setInt (11, bonuses[9]);
preparedStmt.setInt (12, bonuses[10]);
preparedStmt.setInt (13, bonuses[11]);
preparedStmt.setInt (14, bonuses[12]);
preparedStmt.setInt (15, bonuses[13]);
preparedStmt.setInt (16, bonuses[14]);
preparedStmt.setInt (17, bonuses[15]);
preparedStmt.setInt (18, bonuses[16]);
preparedStmt.setInt (19, bonuses[17]);
preparedStmt.execute();
conn.close();
}
catch (Exception e)
{
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
catch (Throwable e) {
Logger.handle(e);
}
log("Finished Unpacking.");
}
}
private static void log(String s) {
System.out.println(s);
}
}
And this is my SQL table setup