Привет всем, пытаюсь сделать парсер, который берет значения из SQL, и записывает в xml, но почему то он записывает только последнее значение, не могу понять почему.. в Таблице 995 записей... при выполнении программы, он пишет в xml 955 раз одно и тоже... Подскажите пожалуста что тут не так? | Код | package my.l2parse;
import java.io.File; import java.io.FileWriter; import java.sql.ResultSet; import java.sql.SQLException;
import javolution.util.FastList; import my.global.db.DatabaseFactory; import my.global.db.DatabaseUtils; import my.global.db.FiltredPreparedStatement; import my.global.db.ThreadConnection;
/** * Парсер Дверей из SQL в XML * * @author Felixx */ public class doorParse { static class Doors { static int id; static String name; static int hp; static int pdef; static int mdef; static int unlockable; static int key; static int level; static int showHp; static int posx; static int posy; static int posz; static int ax; static int ay; static int bx; static int by; static int cx; static int cy; static int dx; static int dy; static int minz; static int maxz; static String siegeweapon; static String geodata; }
static FastList<Doors> LIST = new FastList<Doors>(); static FileWriter DOORS;
public static void main() throws Exception { DOORS = new FileWriter(createFile("doors"), true);
String SS = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<list>\n"; DOORS.write(SS);
LoadFromSQL();
System.out.println("Loaded doors " + LIST.size());
//System.out.println("[doors]: " + LIST.get(0).id); //System.out.println("[doors]: " + LIST.get(1).id); for(Doors doors : LIST) { parse(doors); }
DOORS.write("</list>");
DOORS.close(); }
public static void parse(Doors doors) throws Exception { String BEGIN = "\t<door id=\"" + Doors.id + "\"" + " name=\"" + Doors.name + "\"" + " hp=\"" + Doors.hp + "\"" + " pDef=\"" + Doors.pdef + "\"" + " mDef=\"" + Doors.mdef + "\"" + " unlockable=\"" + Doors.unlockable + "\"" + " key=\"" + Doors.key + "\"" + " level=\"" + Doors.level + "\"" + " showHp=\"" + Doors.showHp + "\"" + " posX=\"" + Doors.posx + "\"" + " posY=\"" + Doors.posy + "\"" + " posZ=\"" + Doors.posz + "\"" + " x1=\"" + Doors.ax + "\"" + " y1=\"" + Doors.ay + "\"" + " x2=\"" + Doors.bx + "\"" + " y2=\"" + Doors.by + "\"" + " x3=\"" + Doors.cx + "\"" + " y3=\"" + Doors.cy + "\"" + " x4=\"" + Doors.dx + "\"" + " y4=\"" + Doors.dy + "\"" + " minZ=\"" + Doors.minz + "\"" + " maxZ=\"" + Doors.maxz + "\"" + " onlySiege=\"" + Doors.siegeweapon + "\"" + " geodata=\"" + Doors.geodata + "\"/>\n";
DOORS.write(BEGIN); }
public static File createFile(String name) throws Exception { File file = new File("./" + name + ".xml"); if( !file.exists()) file.createNewFile(); else { file.delete(); createFile(name); } return file; }
@SuppressWarnings("static-access") public static void LoadFromSQL() { ThreadConnection con = null; FiltredPreparedStatement statement = null; ResultSet rset = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("SELECT * FROM doors ORDER BY `id`"); rset = statement.executeQuery(); while(rset.next()) { Doors doors = new Doors();
doors.id = rset.getInt("id"); doors.name = rset.getString("name"); doors.hp = rset.getInt("hp"); doors.pdef = rset.getInt("pdef"); doors.mdef = rset.getInt("mdef"); doors.unlockable = rset.getInt("unlockable"); doors.key = rset.getInt("key"); doors.level = rset.getInt("level"); doors.showHp = rset.getInt("showHp"); doors.posx = rset.getInt("posx"); doors.posy = rset.getInt("posy"); doors.posz = rset.getInt("posz"); doors.ax = rset.getInt("ax"); doors.ay = rset.getInt("ay"); doors.bx = rset.getInt("bx"); doors.by = rset.getInt("by"); doors.cx = rset.getInt("cx"); doors.cy = rset.getInt("cy"); doors.dx = rset.getInt("dx"); doors.dy = rset.getInt("dy"); doors.minz = rset.getInt("minz"); doors.maxz = rset.getInt("maxz"); doors.siegeweapon = rset.getString("siege_weapon"); doors.geodata = rset.getString("geodata");
LIST.add(doors); System.out.println("[Adding door]: " + doors.id); } } catch(SQLException e) { e.printStackTrace(); } finally { DatabaseUtils.closeDatabaseCSR(con, statement, rset); } } }
|
Добавлено через 2 минуты и 31 секундуhttp://dump.ru/file/3762505Вот табличка, если нужно... Добавлено через 8 минут и 28 секундВот сам проект для Эклпса, на всякий случай... http://plusfile.ru/14981845
|