Pessoal,
Estou tentando inserir no banco dados lidos de uma planilha XLS, porém esse métdodo só está salvando a primeira linha:
package com.fozci.sicorc.service;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.fozci.sicorc.persistence.util.HibernateUtil;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class RazaoService {
/**
*
*/
private static final long serialVersionUID = 1L;
private Session session;
private Transaction tx;
private int i = 0;
private String cd_periodo_temp;
private String cd_ue_temp;
private String cd_ua_temp;
private String cd_reduzido_temp;
private String ds_historico_temp;
private String dt_lrazao_temp;
private String vl_debito_temp;
private String vl_credito_temp;
public void validarArquivo(String name) throws Exception{
Workbook workbook = Workbook.getWorkbook(new File("c:/teste/"+name));
Sheet sheet = workbook.getSheet(0);
//Pega a quantidade de linhas da planilha
int linhas = sheet.getRows();
for(i = 0; i < linhas; i++){
/* pega os valores das células como se numa matriz */
Cell cd_periodo = sheet.getCell(25,i);
Cell cd_ue = sheet.getCell(17,i);
Cell cd_ua = sheet.getCell(20,i);
Cell cd_reduzido = sheet.getCell(11,i);
Cell ds_historico = sheet.getCell(15,i);
Cell dt_lrazao = sheet.getCell(14,i);
Cell vl_debito = sheet.getCell(22,i);
Cell vl_credito = sheet.getCell(23,i);
String cd_periodo_temp = cd_periodo.getContents();
String cd_ue_temp = cd_ue.getContents();
String cd_ua_temp = cd_ua.getContents();
String cd_reduzido_temp = cd_reduzido.getContents();
String ds_historico_temp = ds_historico.getContents();
String dt_lrazao_temp = dt_lrazao.getContents();
String vl_debito_temp = vl_debito.getContents();
String vl_credito_temp = vl_credito.getContents();
this.session = HibernateUtil.getSessionFactory().openSession();
this.tx = this.session.beginTransaction();
Query q = session.createSQLQuery("insert into razao_temp (cd_periodo_temp, cd_ue_temp, cd_ua_temp, cd_reduzido_temp, ds_historico_temp, dt_lrazao_temp, vl_debito_temp, vl_credito_temp)" +
"VALUES('"+cd_periodo_temp+"','"+cd_ue_temp+"','"+cd_ua_temp+"','"+cd_reduzido_temp+"','"+ds_historico_temp+"','"+dt_lrazao_temp+"','"+vl_debito_temp+"','"+vl_credito_temp+"')");
q.executeUpdate();
session.getTransaction().commit();
session.close();
}
workbook.close();
}
}