Jakarta POI

Joined
Dec 11, 2007
Messages
1
Reaction score
0
I have used the Jakarta POI for writing the excel, but it keep promt java.lang.NullPointerException. Any idea for it? My code are as below:

private void proccessSQL(HSSFSheet sheet) {
Statement stmt = null;
ResultSet rs = null;
try {
conn = mshandler.connectDB();
Statement s1 = conn.createStatement();
s1.execute("select count(*) from report");
ResultSet rs1 = s1.getResultSet();
if(rs1.next()) {
int c=0;
c=rs1.getInt(1);
for(int i =1; i <= c ; i++){
try {
stmt = conn.createStatement();
stmt.execute("select * from report_query");
rs = stmt.getResultSet(); // get any ResultSet that came from our query

if(rs.next()) {

String Carrier = rs.getString("Carrier");
HSSFRow row = sheet.getRow(i);
HSSFCell cell = row.getCell((short)0);
if (cell == null)
cell = row.createCell((short)0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(Carrier+""+i);

}

} catch(SQLException sqlExc) {
if (sqlExc.getSQLState().equals("24000")) {
System.out.println(sqlExc.getSQLState());
sqlExc.printStackTrace();
} else {
sqlExc.printStackTrace();
}
}

}
}



} catch(Exception e) {
System.out.println(e);
log.error(e.getMessage());
} finally {
if (rs!=null) {
try {
rs.close();
rs = null;
} catch (Exception e) {}
}
if (stmt!=null) {
try {
stmt.close();
stmt = null;
} catch (Exception e) {}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top