日期:2014-05-18  浏览次数:20603 次

POI读取EXCEL导入数据库后,此EXCEL无法删除文件,请看代码?在线等……
POI读取EXCEL导入数据库CLASS代码:

package   poi;
import   java.io.FileInputStream;
import   java.io.IOException;
import   java.sql.Connection;
import   java.sql.DriverManager;
import   java.sql.SQLException;
import   java.sql.Statement;
import   java.util.*;
import   org.apache.poi.hssf.usermodel.HSSFCell;
import   org.apache.poi.hssf.usermodel.HSSFRow;
import   org.apache.poi.hssf.usermodel.HSSFSheet;
import   org.apache.poi.hssf.usermodel.HSSFWorkbook;
import   org.apache.poi.poifs.filesystem.POIFSFileSystem;


public   class   POITest   {
public   static   Connection   conn   =   null;
public   static   Statement   stmt   =   null;
public   static   boolean   connectDB2()   {
    try   {
      Class.forName( "org.gjt.mm.mysql.Driver ");
      String   url   =   "jdbc:mysql://localhost:3306/dstore ";
      conn   =   DriverManager.getConnection(url, "root ", "111111 ");
      stmt   =   conn.createStatement();
    }
    //捕获加载驱动程序异常
    catch   (ClassNotFoundException   cnfex)   {
      System.err.println( "装载JDBC驱动程序失败。 ");
      cnfex.printStackTrace();
      return   false;
    }
    //捕获连接数据库异常
    catch   (SQLException   sqlex)   {
      System.err.println( "无法连接数据库 ");
      sqlex.printStackTrace();
      //System.exit(1);   //   terminate   program
      return   false;
    }
    return   true;
  }

  public   static   boolean   readExcelToDB2(String   userName)   {
    POIFSFileSystem   fs   =   null;
    HSSFWorkbook   wb   =   null;
    try   {
      fs   =   new   POIFSFileSystem(new   FileInputStream( "E:\\Tomcat   5.0\\webapps\\sms_cnc_rs\\upload\\ "+userName+ ".xls "));
      wb   =   new   HSSFWorkbook(fs);
    }   catch   (IOException   e)   {
      e.printStackTrace();
      return   false;
    }
    HSSFSheet   sheet   =   wb.getSheetAt(0);
    HSSFRow   row   =   null;
    HSSFCell   cell   =   null;
    String   name   =   " ";
    long   aa   =0;
    String