使用Workbook的时候程序停止
代码如下
package com.orange.khglxt;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.orange.khglxt.beans.DbDao;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class DoUpload extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException {
RequestDispatcher rd;
String fileName = (String)request.getAttribute("fileName");
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
System.out.println(fileName);
System.out.println("aaaa");
try {
conn = DbDao.getConnection();
String sql = "select * from clientinfo where clientName = ?";
ps = conn.prepareStatement(sql);
System.out.println("aaaa");
Workbook book = Workbook.getWorkbook(new File(fileName));
System.out.println("aaaa");
Sheet sheet = book.getSheet(0);
int columns = sheet.getColumns();
//定义一个数组来缓存取到的值
String[] cache = {};
System.out.println("bbbb");
for(int j=1;j<columns;j++) {
for(int i=0; i<14; i++) {
Cell cell = sheet.getCell(i,j);
cache[i] = cell.getContents();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date dateTmp = new java.sql.Date(sdf.parse(cache[1]).getTime());
ps.setString(1, cache[2]);
rs = ps.executeQuery();
if(rs.next()) {
String updateSql = "update clientinfo set visitedTime = ?,clientName = ?,contactPerson = ?,position = ?," +
"telnum = ?,mobile = ?,qqNum = ?,address = ?,adSitu = ?,cooIntention = ?," +
"nextVis = ?,noInten = ?,followPerson = ? where clientName = ?";
ps = conn.prepareStatement(updateSql);
ps.setDate(1,dateTmp);
ps.setString(2, cache[2]);
ps.setString(3, cache[3]);
ps.setString(4, cache[4]);
ps.setString(5, cache[5]);
ps.setString(6, cache[6]);
ps.setString(7, cache[7]);
ps.setString(8, cache[8]);
ps.setString(9, cache[9]);
ps.setInt(10, Integer.parseInt(cache[10]));
ps.setString(11, cache[11]);
ps.setString(12, cache[12]);
ps.setString(13, cache[13]);
ps.setString(14, cache[2]);
ps.executeUpdate();
} else {
String insertSql = "insert into clientinfo values(null,?,?,?,?,?,?,?,?,?,?,?,?,?)";
ps = conn.prepareStatement(insertSql);
ps.setDate(1,dateTmp);
ps.setString(2, cache[2]);
ps.setString(3, cache[3]);
ps.setString(4, cache[4]);
ps.setString(5, cache[5]);
ps.setString(6, cache[6]);
ps.setString(7, cache[7]);
ps.setString(8, cache[8]);
ps.setString(9, cache[9]);
ps.setInt(10, Integer.parseInt(cache[10]));
ps.setString(11, cache[11]);
ps.setString(12, cache[12]);
ps.setString(13, cache[13]);
ps.executeUpdate();
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println("cccc");
rd = request.getRequestDispatcher("/test1.jsp");
rd.forward(request,response);
}
}
使用打印的方式可以看到在程序执行到Workbook book = Workbook.getWorkbook(new File(fileName));时程序停止,没有报任何错误,请问是怎么回事?
--------------------编程问答-------------------- 断点跟进去看看发生了什么
补充:Java , Web 开发