Galera eh o seguinte: estou pegando os dados de uma planilha excel e formatando os dados e jogando pra um arquivo de texto. So que esta lancando uma excecao que nao sei qual o problema.
Um exemplo dos registros da minha planilha:
xxxx 11 001 aaa01a
xxxx 01 254 111
o problema da quando eu do um get na quarta coluna.
Se eu dou um getObject em um valor que tem letras e numero(primeira linha) ele funciona, agora se o valor só tem numeros(segunda linha), o getObject nao funciona
Na verdade o que acontece é que ele pega um valor nulo e acaba dando um nullpointer mais pra frente.
Eae. que que eu faço? a excecao eh lancada na ultima linha do codigo, obviamente.
segue um pedaco do codigo:
Connection con;
String user = "sa";
String password = "";
con = DriverManager.getConnection(url, user, password);
Statement comando = con.createStatement();
String consultaSQL = "select * from [altas$]";
ResultSet rs = comando.executeQuery (consultaSQL);
System.out.println("Resultados:");
DataOutputStream out = new DataOutputStream (
new BufferedOutputStream (
new FileOutputStream("c:\\segundafeira.txt")));
// System.out.print(rs);
final String espaco = "\t\t";
String aux_b = "";
while (rs.next())
{
Object b;
Object g, h;
Object c;
Object d;
//Integer c;
//Integer d;
Integer a = new Integer(rs.getInt(1));
b = rs.getObject(2);
//Integer b = new Integer(rs.getInt(2));
if((a==null)||(b==null))break;
//c= new Integer(rs.getInt(3));
c=rs.getObject(3);
//d = rs.getObject(4);
d = new Integer(rs.getInt(4));
Integer e = new Integer(rs.getInt(5));
Integer f = new Integer(rs.getInt(6));
g = rs.getObject(7);
h = rs.getObject(8);
String um="", dois="", tres="";
System.out.println("Processando linha....:"+rs.getRow());
if(a.toString().length()<4)
{
int temp = 4 - a.toString().length();
while (temp > 0)
{
um+=" ";
temp--;
}
}
um+=a.toString();
//um+="\t";
//**********************************************************************
if(b.toString().length()<7)
{
int temp = 7 - b.toString().length();
while (temp > 0)
{
um+=" ";
temp--;
}
}
um+="\t";
um+=b.toString();
//**********************************************************************
if(c.toString().length()<3)