Olá pessoal, sou novo aqui e no java, estou tentando pegar todas as tabelas do banco de dados e salvar num script.
Mas quando rodo o meu programa ele vem com valores duplicados…Irei mandar o codigo.
public class criacaoColunas {
private ArrayList<String> tabelas = null;
private ArrayList<String> colunas = null;
private int index = 0;
private ArrayList<TabelaBean> tabelaSql = null;
private ArrayList<ColunaBean> colunaSql = null;
private ArrayList<String> tempTabela = new ArrayList<String>();
private ArrayList<String> tempColuna = new ArrayList<String>();
private String palavraFormada = "";
private String palavra = "";
private String palavra2 = "";
private String palavra3 = "";
private String palavra4 = "";
private String palavra5 = "";
public criacaoColunas() throws Exception {
DAOTesta dao = new DAOTesta();
colunas = dao.buscaColuna();
colunaSql = dao.separaColuna();
OutputStream os = new FileOutputStream("Coluna.sql");
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
for (int i = 0; i < colunaSql.size(); i++) {
tempColuna.add(i, colunaSql.get(i).getNOME_COL());
}
for (String coluna : colunas) {
String[] abreviacao = coluna.split(" ");
palavraFormada = "";
for (index = 0; index < abreviacao.length; index++) {
int tempIndex = 0;
tempIndex = tempColuna.indexOf(abreviacao[index]);
if (tempIndex >= 0) {
palavra = colunaSql.get(tempIndex).getOWNER_TAB();
palavra2 = colunaSql.get(tempIndex).getNOME_TAB();
palavra3 = colunaSql.get(tempIndex).getNOME_COL();
palavra4 = colunaSql.get(tempIndex).getTIPO_COL();
palavra5 = colunaSql.get(tempIndex).getVLR_DEFAULT();
palavraFormada = palavra + "','" + palavra2 + "','" + palavra3 + "','" + palavra4
+ "','" + palavra5 ;
bw.write(palavraFormada);
bw.newLine();
}
else {
palavraFormada = palavraFormada + " " + abreviacao[index];
bw.write(palavraFormada);
bw.newLine();
}
}
}
}
}
classe dao
public ArrayList buscaColuna() throws SQLException {
ArrayList<String> colunas = new ArrayList<String>();
String sql = "select * from sd_tab_col";// where nome_tab = '" + tabela + "'";
PreparedStatement st = connection2.prepareStatement(sql);
ResultSet rs = st.executeQuery();
while (rs.next()) {
colunas.add(rs.getString("NOME_COL"));
}
rs.close();
st.close();
return colunas;
}
public ArrayList separaColuna() throws SQLException {
ArrayList<ColunaBean> listaColuna = new ArrayList<ColunaBean>();
String sql = "select * from sd_tab_col";
PreparedStatement st = connection2.prepareStatement(sql);
ResultSet rs = st.executeQuery();
while (rs.next()) {
ColunaBean coluna = new ColunaBean();
coluna.setOWNER_TAB(rs.getString("OWNER_TAB"));
coluna.setNOME_TAB(rs.getString("NOME_TAB"));
coluna.setNOME_COL(rs.getString("NOME_COL"));
coluna.setTIPO_COL(rs.getString("TIPO_COL"));
coluna.setVLR_DEFAULT(rs.getString("VLR_DEFAULT"));
listaColuna.add(coluna);
}
rs.close();
st.close();
return listaColuna;
}
e tem a classe bean onde estão os get e set.
Agradeço se alguem puder me ajudar.