0
Hello. I am creating a program whose purpose is to read files. xls and save to the bank, but when I use the read method with Insert, it inserts only 36 lines, without presenting errors. Could you help me?
public Object lerArquivoReliga() throws IOException, BiffException, SQLException, ClassNotFoundException, ParseException{
Workbook workbook = Workbook.getWorkbook(new File("C:\\Users\\Arthur Rodrigues\\Documents\\religa.xls"));
Sheet sheet = workbook.getSheet(0);
int linhas = sheet.getRows() ;
int colunas = sheet.getColumns() ;
try{
for(int l= 0;l < linhas; l++){//linhas
for(int c = 0; c < colunas; c++){//colunas
Cell aGeral = sheet.getCell(c,l);
String colunaGeral = aGeral.getContents();
Dao dao = new Dao();
System.out.println("Testando inicio " + colunaGeral);
ClasseVariaveis cv = new ClasseVariaveis();
Cell coluna0 = sheet.getCell(0, c);
String col0 = coluna0.getContents();
int i0=0;
if(col0!=null){
i0 = Integer.parseInt(col0);
}
cv.setNota(i0);// nota
Cell coluna1 = sheet.getCell(1, c);
String col1 = coluna1.getContents();
cv.setInstalacao(col1);//Instalacao
Cell coluna2 = sheet.getCell(2 , c);
String col2 = coluna2.getContents();
//SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
cv.setCliente(col2);
Cell coluna3 = sheet.getCell(3 , c);
String col3 = coluna3.getContents();
cv.setEndereco(col3);
Cell coluna4 = sheet.getCell(4, c);
String col4 = coluna4.getContents();
cv.setBairro(col4);
Cell coluna5 = sheet.getCell(5, c);
String col5 = coluna5.getContents();
cv.setMedidor(col5);
Cell coluna6 = sheet.getCell(6, c);
String col6 = coluna6.getContents();
cv.setPai(separaPai(col6));
cv.setFilho(separaFilho(col6));
cv.setNeto(separaNeto(col6));
cv.setUnidade_de_leitura(col6);
Cell coluna7 = sheet.getCell(7, c);
String col7 = coluna7.getContents();
cv.setData(col7);
Cell coluna8 = sheet.getCell(8, c);
String col8 = coluna8.getContents();
cv.setHora(col8); //formatar a data
Cell coluna9 = sheet.getCell(9, c);
String col9 = coluna9.getContents();
cv.setTexto(col9);
Cell coluna10 = sheet.getCell(10, c);
String col10 = coluna10.getContents();
cv.setCorte_exec(col10);
Cell coluna11 = sheet.getCell(11, c);
String col11 = coluna11.getContents();
cv.setReliga_exec(col11);
dao.insertRoteirizacao_religa(cv);
System.out.println("Linha" + l + "Coluna" + c);
} return l++;
}
workbook.close();
return "";
}catch(Exception e){
e.printStackTrace();
}return "";
}
Follows the Insert method:
public void insertRoteirizacao_religa(ClasseVariaveis religa)throws SQLException, ClassNotFoundException {
conectar();
pstm=con.prepareStatement("insert into roteirizacao_religa(nota,instalacao,cliente,endereco,bairro,medidor,unidade,data,hora,texto,corte_exec,religa_exec,pai, filho, neto)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") ;
pstm.setInt (1,religa.getNota());
pstm.setString(2, religa.getInstalacao());
pstm.setString(3, religa.getCliente());
pstm.setString(4, religa.getEndereco());
pstm.setString(5,religa.getBairro());
pstm.setString(6, religa.getMedidor());
pstm.setString(7, religa.getUnidade_de_leitura());
pstm.setString(8,religa.getData());
pstm.setString(9, religa.getHora());
pstm.setString(10, religa.getTexto());
pstm.setString(11, religa.getCorte_exec());
pstm.setString(12 , religa.getReliga_exec());
pstm.setString(13, religa.getPai());
pstm.setString(14, religa.getFilho());
pstm.setString(15, religa.getNeto());
pstm.execute();
pstm.close();
desconectar();
}