Você está na página 1de 3

Workbook workbook = null;

try
{
workbook = Workbook.getWorkbook(new File("Fornecedore.xls"));
}
catch (IOException ex)
{
Logger.getLogger(Teste_Importacao.class.getName()).log(Level.SEVERE,
null, ex);
}
catch (BiffException ex)
{
Logger.getLogger(Teste_Importacao.class.getName()).log(Level.SEVERE,
null, ex);
}
Sheet sheet = workbook.getSheet(0);
int linhas = sheet.getRows();
System.out.println("Iniciando a leitura da planilha XLS:");
for(int i = 0; i < linhas; i++){
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell
Cell

a1 = sheet.getCell(0, i);
a2 = sheet.getCell(1, i);
a3 = sheet.getCell(2, i);
a4 = sheet.getCell(3, i);
a5 = sheet.getCell(4, i);
a6 = sheet.getCell(5, i);
a7 = sheet.getCell(6, i);
a8 = sheet.getCell(7, i);
a9 = sheet.getCell(8, i);
a10 = sheet.getCell(9, i);
a11 = sheet.getCell(10, i);
a12 = sheet.getCell(11, i);
a13 = sheet.getCell(12, i);
a14 = sheet.getCell(13, i);
a15 = sheet.getCell(14, i);

String
String
String
String
String
String
String
String
String
String
String
String
String
String
String

as1 = a1.getContents();
as2 = a2.getContents();
as3 = a3.getContents();
as4 = a4.getContents();
as5 = a5.getContents();
as6 = a6.getContents();
as7 = a7.getContents();
as8 = a8.getContents();
as9 = a9.getContents();
as10 = a10.getContents();
as11 = a11.getContents();
as12 = a12.getContents();
as13 = a13.getContents();
as14 = a14.getContents();
as15 = a15.getContents();

System.out.println("Coluna 1: " + as1);


System.out.println("Coluna 2: " + as2);

System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna
System.out.println("Coluna

3: " + as3);
4: " + as4);
5: " + as5);
6: " + as6);
7: " + as7);
8: " + as8);
9: " + as9);
10: " + as10);
11: " + as11);
12: " + as12);
13: " + as13);
14: " + as14);
15: " + as15);

try
{
Class.forName(driverName);
conn = DriverManager.getConnection(databaseURL1,user,password);
stmt = conn.createStatement();
}
catch (ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null, "Classe no foi encontrada: "+e.getMes
sage(), "ERRO", JOptionPane.INFORMATION_MESSAGE);
}
catch (SQLException e)
{
JOptionPane.showMessageDialog(null, "ERRO SQL: "+e.getMessage(), "ERRO",
JOptionPane.INFORMATION_MESSAGE);
}
java.sql.Date data = null;
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
try
{
data = new java.sql.Date(format.parse("01/05/1995").getTime());
}
catch (ParseException ex)
{
Logger.getLogger(Teste_Importacao.class.getName()).log(Level.SEVERE,
null, ex);
}
try
{
stmt.execute("INSERT INTO FORNECEDOR(CODIGO, NOME, CPF, CNPJ, RG, IN
SCR, FANTASIA, ENDERECO, NUM, COMPLEMENTO, BAIRRO, CIDADE,"
+ "CEP, ESTADO, FONE, FAX, VENDEDOR, FONEVENDEDOR, RECAD
O, REPRESENTANTE, EMAIL, WEB, OBS) "
+ "VALUES('"+Integer.parseInt(as1)+"','"+as5+"','','"+as
2+"','"+as3+"','"+as4+"','"+as6+"','"+as7+"','"+as8+"',"
+ "'"+as9+"','"+as10+"','"+as11+"','"+as12+"','','"+as13
+"','"+as14+"','','','','','"+as15+"','','')");
}
catch (SQLException ex)
{
Logger.getLogger(Teste_Importacao.class.getName()).log(Level.SEVERE,
null, ex);
}
}

workbook.close();

Você também pode gostar