求一将Excel的数据导到数据库中的程序,紧急,在线等待中!
求一Excel的数据导到数据库中的程序,
Excel 中有几个sheet , 单元格中还可能含有图片等文档 ,
数据库为oracle, 其他数据库的也行,
我暂时用的是JXL ,
也有人用POI或其他的,都可以,只要达到要求就行了,因为比较紧,没时间挑三检四,功能第一先.
如上,给出程序代码的(连接的也可以) 立马 给分.
先谢谢各位了^^^^^^
------解决方案--------------------使用jxl.jar的api函数可以比较轻松的完成
------解决方案--------------------//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
package com.inventec.cmm.shopimport;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JOptionPane;
import java.io.File;
//import
org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import java.lang.*;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
;
/**
* MyEclipse Struts
* Creation date: 02-18-2006
*
* XDoclet definition:
* @struts:action validate= "true "
*/
public class DoImportAction extends Action {
// --------------------- Instance Variables
// --------------------- Methods
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute (
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
// Logger logger =Logger.getLogger( "DoatProAction.class ");
Collection errors = new ArrayList();
String id= "-1 ";
if (request.getParameter( "id ")==null){
errors.add( "请登陆! ");
return mapping.getInputForward();
}else
id=request.getParameter( "id ");
request.setAttribute( "id ",request.getParameter( "id "));
// int isnull =0;
int cnt=0;
String dir=servlet.getServletContext().getRealPath( "/upload ");
ShopImportForm hff=(ShopImportForm)form;
FormFile file =(FormFile) hff.getFile();
if((file==null)||(file.getFileSize()==0))
{
errors.add( "文件上传出错或者未指定文件! ");
request.setAttribute( "errors ",errors);
return mapping.getInputForward();
}
String fname=file.getFileName();
String size=Integer.toString(file.getFileSize())+ "bytes ";
InputStream streamIn=file.getInputStream();
java.text.DateFormat d = new java.text.SimpleDateFormat( "yyyy-MM-dd-hh_mm_ss ");
String strd = d.format(new Date(System.currentTimeMillis()));
S