java把excel文件导入数据库报错!!
publicvoidgetDate(){Listliststu=newArrayList();//找到导入的文件InputStreamis=Date.class.getC...
public void getDate() {
List liststu = new ArrayList();
// 找到导入的文件
InputStream is = Date.class.getClassLoader().getResourceAsStream(
"N3单词分类表(1).xls");
try {
// 创建工作簿
Workbook wb = Workbook.getWorkbook(is);
// 创建工作表
jxl.Sheet sheet = wb.getSheet(0);
String content = null;
for (int i = 0; i < sheet.getRows(); i++) {
Characters characters = new Characters();
for (int j = 0; j < sheet.getColumns(); j++) {
content = sheet.getCell(j, i).getContents();
System.out.print(content);
if (characters.getId() == 0) {
characters.setId(Integer.parseInt(sheet.getCell(j, i)
.getContents().trim()));
continue;
}
if (characters.getPronunciation() == null) {
characters.setPronunciation(sheet.getCell(j, i)
.getContents());
continue;
}
if (characters.getCharacters() == null) {
characters.setCharacters(sheet.getCell(j, i)
.getContents());
continue;
}
if (characters.getMeaning() == null) {
characters
.setMeaning(sheet.getCell(j, i).getContents());
continue;
}
}
insert(characters);
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void insert(Characters characters) {
String sql = "insert into characters values(" + characters.getId()
+ ",'" + characters.getPronunciation() + "','"
+ characters.getCharacters() + "','" + characters.getMeaning()
+ "')";
ConnCOnnection conn = new ConnCOnnection();
Connection con = conn.getConnect();
try {
Statement state = con.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at net.company.dao.Date.getDate(Date.java:41)
at net.company.server.ExcelServer.getDate(ExcelServer.java:10)
at net.company.servlet.ExcelServlet.ExcelToMySql(ExcelServlet.java:40)
at net.company.servlet.ExcelServlet.doPost(ExcelServlet.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 展开
List liststu = new ArrayList();
// 找到导入的文件
InputStream is = Date.class.getClassLoader().getResourceAsStream(
"N3单词分类表(1).xls");
try {
// 创建工作簿
Workbook wb = Workbook.getWorkbook(is);
// 创建工作表
jxl.Sheet sheet = wb.getSheet(0);
String content = null;
for (int i = 0; i < sheet.getRows(); i++) {
Characters characters = new Characters();
for (int j = 0; j < sheet.getColumns(); j++) {
content = sheet.getCell(j, i).getContents();
System.out.print(content);
if (characters.getId() == 0) {
characters.setId(Integer.parseInt(sheet.getCell(j, i)
.getContents().trim()));
continue;
}
if (characters.getPronunciation() == null) {
characters.setPronunciation(sheet.getCell(j, i)
.getContents());
continue;
}
if (characters.getCharacters() == null) {
characters.setCharacters(sheet.getCell(j, i)
.getContents());
continue;
}
if (characters.getMeaning() == null) {
characters
.setMeaning(sheet.getCell(j, i).getContents());
continue;
}
}
insert(characters);
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void insert(Characters characters) {
String sql = "insert into characters values(" + characters.getId()
+ ",'" + characters.getPronunciation() + "','"
+ characters.getCharacters() + "','" + characters.getMeaning()
+ "')";
ConnCOnnection conn = new ConnCOnnection();
Connection con = conn.getConnect();
try {
Statement state = con.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at net.company.dao.Date.getDate(Date.java:41)
at net.company.server.ExcelServer.getDate(ExcelServer.java:10)
at net.company.servlet.ExcelServlet.ExcelToMySql(ExcelServlet.java:40)
at net.company.servlet.ExcelServlet.doPost(ExcelServlet.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询