excel文档数据导入到sql2005数据库对应表中
jsp页面上传一个excel文档,将excel的内容对应写入到sql2005的数据表中,怎样实现,知道的说一下,有这方面资料例子的麻烦发给我一下,1665688718@qq.com --------------------编程问答-------------------- 利用jxl或者poi解析excel的内容,然后利用JDBC操作根据定义的规则导入到数据表就可以了 --------------------编程问答-------------------- 使用poi吧--------------------编程问答-------------------- 不知道怎么用啊,大伙有实际的例子没,我这里jsp页面上传一张excel表格,要将里面的数据对应导入到sql2005的一张表中 --------------------编程问答-------------------- /**
* 获得的集合添加到数据库中并返回一个object二维数组
* @param list
* @return
*/
private Object[][] addGongZi(List list,String date){
Object[][] obj=null;
StringBuffer sql=new StringBuffer();
sql.append("insert into GongZi ");
if(list!=null&&list.size()>0){
obj=new Object[list.size()][21];
for(int i=0;i<list.size();i++){
obj[i]=(Object[])list.get(i);
obj[i][19]=date;
obj[i][20]="0";
if(i==list.size()-1){
sql.append("select '"+obj[i][18]+"','"+obj[i][0]+"','"+obj[i][1]+"','"+
obj[i][2]+"',"+obj[i][3]+","+obj[i][4]+","+obj[i][5]+","+
obj[i][6]+","+obj[i][7]+","+obj[i][8]+","+obj[i][9]+","+
obj[i][10]+","+obj[i][11]+","+obj[i][12]+","+obj[i][13]+","+
obj[i][14]+","+obj[i][15]+","+obj[i][16]+",'"+obj[i][17]+"','"+
obj[i][19]+"','"+obj[i][20]+"'");
}else{
sql.append("select '"+obj[i][18]+"','"+obj[i][0]+"','"+obj[i][1]+"','"+
obj[i][2]+"',"+obj[i][3]+","+obj[i][4]+","+obj[i][5]+","+
obj[i][6]+","+obj[i][7]+","+obj[i][8]+","+obj[i][9]+","+
obj[i][10]+","+obj[i][11]+","+obj[i][12]+","+obj[i][13]+","+
obj[i][14]+","+obj[i][15]+","+obj[i][16]+",'"+obj[i][17]+"','"+
obj[i][19]+"','"+obj[i][20]+"' union ");
}
}
dao.updateEntityBySql(sql.toString());
}
return obj;
} --------------------编程问答-------------------- 不知道lz能不能看懂 --------------------编程问答-------------------- 楼主写出来没 我现在也同问啊 有的话给我看看 --------------------编程问答--------------------
--------------------编程问答-------------------- jxl做的
File f = new File(path("execl文件的路径") + "\\" + name("execl文件名称"));
Workbook rwb = null;
List<Gaokaochengji> gkList = new ArrayList<Gaokaochengji>();
InputStream ist = new FileInputStream(f);
rwb = Workbook.getWorkbook(ist);
Sheet sheet = rwb.getSheet(0);
int cols = sheet.getColumns();
int rows = sheet.getRows();
for (int i = 2; i < rows; i++) {
String column[] = new String[cols];
Cell[] row = sheet.getRow(i);
for (int j = 0; j < row.length; j++) {
column[j] = row[j].getContents();
}
Gaokaochengji gaokao = new Gaokaochengji();
gaokao.setSid(Integer.parseInt(column[0]));
gaokao.setName(column[1]);
gaokao.setXuehao(column[2]);
gaokao.setWenlike(column[3]);
gaokao.setClass_(column[4]);
gaokao.setYuwen(Double.parseDouble(column[5]));
gaokao.setShuxue(Double.parseDouble(column[6]));
gaokao.setWaiyu(Double.parseDouble(column[7]));
gaokao.setWenlizonghefen(Double.parseDouble(column[8]));
gaokao.setZongfen(Double.parseDouble(column[9]));
gaokao.setTijian(column[10]);
gaokao.setTechang(column[11]);
gaokao.setGaokaoshangxian(column[12]);
gaokao.setSchoolid(uid);
gaokao.setYear(year);
gkList.add(gaokao);
}
gkdDao.addGaokaochengji(gkList);
ist.close();
rwb.close();
补充:Java , Web 开发