I would like a help, I need to change a status of a field in a table, after generating an xml using XStream. How could I do to update the table? At the very moment of executing the xml, or after adding all objects to the list.
public class CriarXmlSqlPessoa {
public static void main(String[] args) throws IOException {
XStream xstream = new XStream(new DomDriver("UTF8", new NoNameCoder()));
xstream.alias("contatos", List.class);
xstream.alias("contato", Pessoa.class);
ArrayList<Pessoa> pessoas;
pessoas = new ArrayList<Pessoa>();
Connection conexao = null;
new FabricaConexaoMysql();
try {
conexao = FabricaConexaoMysql.criarConexao();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSet rs = null;
try {
rs = FabricaConexaoMysql.executarSelect(conexao, "SELECT * FROM Pessoa");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(rs.next()) {
pessoas.add(
new Pessoa(rs.getInt("id"),
rs.getString("nome"),
rs.getInt("idade"),
rs.getString("status")
)
);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String contatosEmXml = xstream.toXML(pessoas);
PrintWriter arquivo = new PrintWriter(new BufferedWriter(new FileWriter("C:\saida.xml")));
arquivo.println(contatosEmXml);
arquivo.close();
}