Pessoal estou tendo essa excessão no meu código, ele le de uma planilha do excel datas e dados e atualiza meu banco de dados, porém apenas a primeira célula é lida, depois tenho a excessão de Null…
import java.io.File;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.*;
import jxl.*;
import jxl.read.biff.*;
import java.text.*;
public class excel {
private String url;
private Connection connection;
//Vector dados = new Vector();
/** Creates a new instance of excel */
public excel() {
try {
url = "jdbc:odbc:Paschoetoserieshistoricas";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
connection = DriverManager.getConnection( url );
} catch ( ClassNotFoundException cnfex ) {
// porcessa ClassNotFoundExceptions aqui
cnfex.printStackTrace();
} catch ( SQLException sqlex ) {
// processa SQLExceptions aqui
sqlex.printStackTrace();
} catch ( Exception ex ) {
// processa exeptions remanescentes aqui
ex.printStackTrace();
}
}
public void AbrePlanilha(){
try{
Workbook workbook = Workbook.getWorkbook(new File("JavaExcel.xls"));
Sheet sheet = workbook.getSheet(0);
String numbera2 = null;
double numberb2 = 0;
int ja = 0;
int ia = 0;
int jb = 1;
int ib = 0;
while (!sheet.getCell(ja,ia).getContents().equals("") && !sheet.getCell(jb,ib).getContents().toString().equals("")){//[b]Aqui acontece a excessao após a primeira passagem![/b]
Cell a2 = sheet.getCell(ja,ia);
Cell b2 = sheet.getCell(jb,ib);
if (b2.getType() == CellType.NUMBER) {
NumberCell nc = (NumberCell) b2;
numberb2 = nc.getValue();
}
if (a2.getType() == CellType.LABEL) {
numbera2 = a2.getContents();
}
java.util.Date dt = new java.util.Date();
SimpleDateFormat formatador = new SimpleDateFormat ("dd/MM/yyyy");
try
{
dt = formatador.parse (numbera2);
}
catch (Exception e)
{
e.printStackTrace();
}
java.sql.Date sqlDate = new java.sql.Date (dt.getTime());
PreparedStatement pstmt0 = connection.prepareStatement("SELECT ID FROM TbSeries WHERE Nome = ?");
pstmt0.setObject(1, "BRL");
ResultSet rs0 = pstmt0.executeQuery();
boolean ret = rs0.next();
int IDSerie = rs0.getInt("ID");
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO TbValorSerie( Data , Valor, IDSerie) VALUES ( ?, ?, ?)");
//java.sql.Date dt = new java.sql.Date ((long)numbera2);
//pstmt.setDate (1, dt);
pstmt.setDate(1, sqlDate);
pstmt.setDouble(2, numberb2);
pstmt.setInt(3, IDSerie);
int rs = pstmt.executeUpdate();
if (rs == 1){
System.out.println("inserção realizada\n");
}
workbook.close();
//pstmt.close();
ia++;
ib++;
}
} catch (IOException e){
e.printStackTrace();
} catch (BiffException be){
be.printStackTrace();
} catch (SQLException ex){
ex.printStackTrace();
}
}
public static void main(String[] args){
excel ex = new excel();
ex.AbrePlanilha();
}
}