Reading from Excel sheet
I am trying to read a single column of data from an Excel sheet.
My Excel looks like this:
appnum
100
200
abc201
300
def301
400
500
My Excel sheet is called "appnumbers.xls" and the sheet is also called "appnumbers".
I have created the DSN and called it "appnumbers".
This is my code:
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
publicclass readExcel
{
publicstaticvoid main( String [] args )
{
Connection c =null;
Statement stmnt =null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection("jdbc:odbc:appnumbers","","" );
stmnt = c.createStatement();
String query ="select appnum from [appnumbers$]";
ResultSet rs = stmnt.executeQuery( query );
System.out.println("Found the following app numbers:" );
while( rs.next() )
{
System.out.println( rs.getString("appnum" ) );
}
}
catch( Exception e )
{
System.err.println( e );
}
finally
{
try
{
stmnt.close();
c.close();
}
catch( Exception e )
{
System.err.println( e );
}
}
}
}
The output is as follows:
100.0
200.0
null
300.0
null
400.0
500.0
1. Why do the numbers appear like integers (100 shows up as 100.0)?
2. Why do the aplhanumeric characters appear as null?

