`
ZhengMingwei
  • 浏览: 135180 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Ecxel数据导入Oracle 数据库中

阅读更多

package com.icss.util.readToDB;

 

 

//Oracle 数据库中JNNQ中的表名的类


public final class JNNQTableNames {
  
   public static final String nq_schedule_info="nq_schedule_info";
   public static final String enterprise_info="enterprise_info";
   public static final String jd_nzwbzmjyxdc="jd_nzwbzmjyxdc";
   public static final String jd_qdbmjyj="jd_qdbmjyj";
   public static final String jd_qnlsjzyjjzwclyj="jd_qnlsjzyjjzwclyj";
    ... ...   
 
}

 

package com.icss.util.readToDB;

 

//向数据库操作 数据的sql 语句类

public  class InsertInToOracleSqls {

 

//该方法为获得相应表中插入数据的sql语句的获取方法

 public String getInsertSqlForOracle(String tableName){

  String sql = null;
  if("nq_schedule_info".equals(tableName)){  //6
     sql="insert into nq_schedule_info values (?,?,?,?,?,?)";
  }else if("enterprise_info".equals(tableName)){
     sql="insert into enterprise_info values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("jd_nzwbzmjyxdc".equals(tableName)){ //68
     sql="insert into jd_nzwbzmjyxdc values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("jd_qdbmjyj".equals(tableName)){    //32
     sql="insert into jd_qdbmjyj values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("jd_qnlsjzyjjzwclyj".equals(tableName)){    //194
     sql="insert into jd_qnlsjzyjjzwclyj values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("jd_qnnzwbzmjyj".equals(tableName)){    //107
     sql="insert into jd_qnnzwbzmjyj values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("jd_xlxsyczclyj".equals(tableName)){    //29
     sql="insert into jd_xlxsyczclyj values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_ym1_ymmjlsqkdcb".equals(tableName)){  //13
     sql="insert into nq_ym1_ymmjlsqkdcb values (?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_ym2_ymmqdcb".equals(tableName)){  //17
     sql="insert into nq_ym2_ymmqdcb values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_ym3_ymyjclhsyb".equals(tableName)){  //17
     sql="insert into nq_ym3_ymyjclhsyb values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_ym4_ymscsyyjb".equals(tableName)){  //12
     sql="insert into nq_ym4_ymscsyyjb values (?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_z7_nzwyqxzhszqkb".equals(tableName)){  //34
     sql="insert into nq_z7_nzwyqxzhszqkb values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_z8_nzwyqxzhssqkb".equals(tableName)){  //15
     sql="insert into nq_z8_nzwyqxzhssqkb values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("nq_zw_raq_table".equals(tableName)){  //4
     sql="insert into nq_zw_raq_table values (?,?,?,?)";
  }else if("nyzycpscqk".equals(tableName)){    //117
     sql="insert into nyzycpscqk values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("qnnzwclyj".equals(tableName)){    //202
     sql="insert into qnnzwclyj values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  }else if("rd_nsi_day".equals(tableName)){  //3
     sql="insert into rd_nsi_day values (?,?,?)";
  }else if("report_directory".equals(tableName)){  //9
     sql="insert into report_directory values (?,?,?,?,?,?,?,?,?)";
  }
   
  return sql;
 }
}

 

 

 

package com.icss.util.readToDB;

import java.sql.PreparedStatement;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

 

 
//该类用于从不同表中的数据存放到Excel中,
//在导入Oracle数据库空中的相应的表
//对应的方法

public class MethodsToTables {

 

 

 //插入Nq_schedule_info表中的数据
 public void setNq_schedule_infoTableValues(Connection conn,PreparedStatement pst,HSSFSheet aSheet,DecimalFormat df){  
  try{
     int p1=0,p0 = 0;
       String p4 = "";
       String p3="";
       String s2 = null,s5=null;
     for (int rowNumOfSheet = 0; rowNumOfSheet <= aSheet
       .getLastRowNum(); rowNumOfSheet++) {
       if (null != aSheet.getRow(rowNumOfSheet)) {
       HSSFRow aRow = aSheet.getRow(rowNumOfSheet);

       //System.out.println(">>>getFirstCellNum < < <"+ 
       //aRow.getFirstCellNum());
       //System.out.println(">>>getLastCellNum < < <"+
       // aRow.getLastCellNum());

      
       for (short cellNumOfRow = 0; cellNumOfRow <= aRow
         .getLastCellNum(); cellNumOfRow++) {

         if (null != aRow.getCell(cellNumOfRow)) {
         HSSFCell aCell = aRow.getCell(cellNumOfRow);

         int cellType = aCell.getCellType();
         String strCell;
         System.out.println(cellNumOfRow+"     cellType :+++++++++++++++"+cellType);
         switch (cellType) {
         case 0://Numeric
            strCell = df.format(aCell
             .getNumericCellValue());

           System.out.println("strCell0===============:"+strCell);
           if(0==cellNumOfRow) p0=Integer.parseInt(strCell);
           if(1==cellNumOfRow) p1=Integer.parseInt(strCell);
           if(3==cellNumOfRow) p3=strCell;//Integer.parseInt(strCell);
           if(4==cellNumOfRow) p4=strCell;//nteger.parseInt(strCell);
           break;
         case 1://String
           strCell = aCell.getStringCellValue();

           System.out.println("strCell1¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥:"+strCell);
           if(2==cellNumOfRow) s2=strCell;
           if(5==cellNumOfRow) s5=strCell;
           break;
         default:
        if(0==cellNumOfRow) p0=0;
           if(3==cellNumOfRow) p3="";
           if(1==cellNumOfRow) p1=0;
//         if(3==cellNumOfRow) p3=0;
           if(4==cellNumOfRow) p4="";
           if(2==cellNumOfRow) s2="";
           if(5==cellNumOfRow) s5="";

         System.out.println("格式不对不读");//其它格式的数据
        
         }

         }

       }
       System.out.println("pppppppppppppppppppppppppppp"+p0+"  "+p1+"  "+p3+"  "+p4+"  "+s2+"  "+s5+"  ");
       pst.setInt(1,  p0);
       pst.setInt(2, p1);
       pst.setString(3, s2);
//       pst.setInt(3, p3);
       pst.setString(4, p3);
       pst.setString(5, p4);
       pst.setString(6, s5);
       pst.execute();
       conn.commit();
       }
     }
  }catch(Exception e){
   e.printStackTrace();
  }   
 }
 
 //
 
 //插入ENTERPRISE_INFO表中的数据
 public void setENTERPRISE_INFOTableValues(Connection conn,PreparedStatement pst,HSSFSheet aSheet,DecimalFormat df){  
  System.out.println("setENTERPRISE_INFOTableValues---->");
  try{
       //int p1=0,p0 = 0;

    int f1=0,f2=0,f5=0,f6=0,f7=0,f8=0,f9=0,f10=0,f11=0,f12=0,f13=0,f14=0;
       String s2 = null,s5=null;
       String p0="",p1="",p2="",p3="",p4="",p5="",p6="",p7="",p8="",p9="",p10="",p11="",p12="",p13="",p14="",p15="";
       String ID="",LEVELL="";
       String CODE="",NAME="",SHORT_NAME="",NQ="",MH="",DD="",YL="",JDX="",IS_ZCQ="",AREA="",TL="",SC="",TYPE="",TEXT="";
      
      
     for (int rowNumOfSheet = 0; rowNumOfSheet <= aSheet
       .getLastRowNum(); rowNumOfSheet++) {
       if (null != aSheet.getRow(rowNumOfSheet)) {
        System.out.println(rowNumOfSheet+"/"+aSheet.getLastRowNum());
       HSSFRow aRow = aSheet.getRow(rowNumOfSheet);

       //System.out.println(">>>getFirstCellNum < < <"+
       // aRow.getFirstCellNum());
       //System.out.println(">>>getLastCellNum < < <"+
       // aRow.getLastCellNum());

      
       for (short cellNumOfRow = 0; cellNumOfRow <= aRow
         .getLastCellNum(); cellNumOfRow++) {

         if (null != aRow.getCell(cellNumOfRow)) {
         HSSFCell aCell = aRow.getCell(cellNumOfRow);

         int cellType = aCell.getCellType();
         String strCell;
         System.out.println(cellNumOfRow+"     cellType :+++++++++++++++"+cellType);

         switch (cellType) {
         case 0://Numeric
            strCell = df.format(aCell
             .getNumericCellValue());

           System.out.println("strCell0===============:"+strCell);
           if(0==cellNumOfRow) f1=Integer.parseInt(strCell);
           if(1==cellNumOfRow) f2=Integer.parseInt(strCell);
           if(4==cellNumOfRow) f5=Integer.parseInt(strCell);
           if(5==cellNumOfRow) f6=Integer.parseInt(strCell);
           if(6==cellNumOfRow) f7=Integer.parseInt(strCell);
           if(7==cellNumOfRow) f8=Integer.parseInt(strCell);
           if(8==cellNumOfRow) f9=Integer.parseInt(strCell);
           if(9==cellNumOfRow) f10=Integer.parseInt(strCell);
           if(10==cellNumOfRow) f11=Integer.parseInt(strCell);
           if(11==cellNumOfRow) f12=Integer.parseInt(strCell);
           if(12==cellNumOfRow) f13=Integer.parseInt(strCell);
           if(13==cellNumOfRow) f14=Integer.parseInt(strCell);

         //if(3==cellNumOfRow) p3=strCell;//Integer.parseInt(strCell);
         //if(4==cellNumOfRow) p4=strCell;//nteger.parseInt(strCell);
           break;
        // case 1://String
         case 1://String
           strCell = aCell.getStringCellValue();

           System.out.println("strCell1¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥:"+strCell);
//         if(0==cellNumOfRow) p0=strCell;
//         if(1==cellNumOfRow) p1=strCell;
           if(2==cellNumOfRow) p2=strCell;
           if(3==cellNumOfRow) p3=strCell;
//         if(4==cellNumOfRow) p4=strCell;
           if(5==cellNumOfRow) p5=strCell;
           if(6==cellNumOfRow) p6=strCell;
           if(7==cellNumOfRow) p7=strCell;
           if(8==cellNumOfRow) p8=strCell;
           if(9==cellNumOfRow) p9=strCell;
           if(10==cellNumOfRow) p10=strCell;
           if(11==cellNumOfRow) p11=strCell;
           if(12==cellNumOfRow) p12=strCell;
           if(13==cellNumOfRow) p13=strCell;
           if(14==cellNumOfRow) p14=strCell;
//           if(15==cellNumOfRow) p15=strCell;
          
           break;
         default:
        if(0==cellNumOfRow) p0="0";
           if(1==cellNumOfRow) p1="0";
           if(2==cellNumOfRow) p2="";
           if(3==cellNumOfRow) p3="";
           if(4==cellNumOfRow) p4="";
           if(5==cellNumOfRow) p5="";
           if(6==cellNumOfRow) p6="0";
           if(7==cellNumOfRow) p7="0";
           if(8==cellNumOfRow) p8="0";
           if(9==cellNumOfRow) p9="0";
           if(10==cellNumOfRow) p10="0";
           if(11==cellNumOfRow) p11="0";
           if(12==cellNumOfRow) p12="0";
           if(13==cellNumOfRow) p13="0";
           if(14==cellNumOfRow) p14="0";
//           if(15==cellNumOfRow) p15="";

         System.out.println("格式不对不读");//其它格式的数据
        
         }

         }

       }
       System.out.println("pppppppppppppppppppppppppppp"+p0+"  "+p1+"  "+p3+"  "+p4+"  "+s2+"  "+s5+"  ");
      // pst.setString(1, p0);
       pst.setInt(1, f1);
      // pst.setString(2, p1);
       pst.setInt(2,f2);
       pst.setString(3, p2);
       pst.setString(3, p3);
       pst.setString(4, p3);
     //  pst.setString(5, p4);
       pst.setInt(5,f5);

       pst.setInt(6,f6);
       pst.setInt(7,f7);
       pst.setInt(8,f8);
       pst.setInt(9,f9);
       pst.setInt(10,f10);
       pst.setInt(11,f11);
       pst.setInt(12,f12);
       pst.setInt(13,f13);
       pst.setInt(14,f14);
       pst.setString(15, p14);
       pst.setString(16, p15);

       pst.execute();
       conn.commit();
       }
     }
  }catch(Exception e){
   e.printStackTrace();
  }   

 

   ...  ...
 }
 

package com.icss.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;

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 com.icss.util.readToDB.InsertInToOracleSqls;
import com.icss.util.readToDB.JNNQTableNames;
import com.icss.util.readToDB.MethodsToTables;

 

 

//该Main方法类 用来为执行的程序调用数据的插入
public class exlFile {

 

  //本地文件的存放位置:
   public static String outputFile = "E:\\NQ_SCHEDULE_INFO.xls";

 //public static String fileToBeRead = "E:\\NQ_SCHEDULE_INFO.xls";
 //public static String fileToBeRead = "E:\\test\\ENTERPRISE_INFO.xls";
 //public static String fileToBeRead = "E:\\test\\NQ_REPORT_CROPS.xls";
 //public static String fileToBeRead = "E:\\test\\NQ_REPORT_TARGET.xls";
 //public static String fileToBeRead = "E:\\test\\NQ_REPORTFILL_STATE.xls";
 //public static String fileToBeRead = "E:\\test\\NQ_TARGET_INFO.xls";
 //public static String fileToBeRead = "E:\\test\\NQ_ZW_RAQ_TABLE.xls";
 //public static String fileToBeRead = "E:\\test\\RD_NSI_DAY.xls"; 
 //public static String fileToBeRead = "E:\\test\\REPORT_DIRECTORY.xls";

 //public static String fileToBeRead = "E:\\test\\NQ_CROPS_INFO.xls"; 

 


   public static String fileToBeRead = "E:\\test\\QNNZWCLYJ.xls";
 

//创建Excel文件的方法:
 public void CreateExcel() {
   try {
   // 创建新的Excel 工作簿
   HSSFWorkbook workbook = new HSSFWorkbook();
   // 在Excel工作簿中建一工作表,其名为缺省值
   // 如要新建一名为"效益指标"的工作表,其语句为:
   // HSSFSheet sheet = workbook.createSheet("效益指标");
   HSSFSheet sheet = workbook.createSheet();
   // 在索引0的位置创建行(最顶端的行)
   HSSFRow row = sheet.createRow((short) 0);
   //在索引0的位置创建单元格(左上端)
   HSSFCell cell = row.createCell((short) 0);
   // 定义单元格为字符串类型
   cell.setCellType(HSSFCell.CELL_TYPE_STRING);
   // 在单元格中输入一些内容
   cell.setCellValue("sweater");
   // 新建一输出文件流
   FileOutputStream fOut = new FileOutputStream(outputFile);
   // 把相应的Excel 工作簿存盘
   workbook.write(fOut);
   fOut.flush();
   // 操作结束,关闭文件
   fOut.close();
   System.out.println("文件生成...");

   } catch (Exception e) {
   System.out.println("已运行 xlCreate() : " + e);
   }
 }


public void readExcel() {
  //将被表示成1.3922433397E10的手机号转化为13922433397,不一定是最好的转换方法
  DecimalFormat df = new DecimalFormat("#");

  try {
  // 创建对Excel工作簿文件的引用
  HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
    fileToBeRead));
  //System.out
  //  .println("===SheetsNum===" + workbook.getNumberOfSheets());//获取sheet数
  for (int numSheets = 0; numSheets < workbook.getNumberOfSheets(); numSheets++) {
    if (null != workbook.getSheetAt(numSheets)) {
    HSSFSheet aSheet = workbook.getSheetAt(numSheets);//获得一个sheet
    //System.out.println("+++getFirstRowNum+++" +
    // aSheet.getFirstRowNum());//
    //System.out.println("+++getLastRowNum+++" +
    // aSheet.getLastRowNum());

    for (int rowNumOfSheet = 0; rowNumOfSheet <= aSheet
      .getLastRowNum(); rowNumOfSheet++) {
      if (null != aSheet.getRow(rowNumOfSheet)) {
      HSSFRow aRow = aSheet.getRow(rowNumOfSheet);

      //System.out.println(">>>getFirstCellNum < < <"+
      // aRow.getFirstCellNum());
      //System.out.println(">>>getLastCellNum < < <"+
      // aRow.getLastCellNum());
      for (short cellNumOfRow = 0; cellNumOfRow <= aRow
        .getLastCellNum(); cellNumOfRow++) {

        if (null != aRow.getCell(cellNumOfRow)) {
        HSSFCell aCell = aRow.getCell(cellNumOfRow);

        int cellType = aCell.getCellType();
        System.out.println(cellNumOfRow+"     cellType :"+cellType);
        switch (cellType) {
        case 0://Numeric
          String strCell = df.format(aCell
            .getNumericCellValue());

          System.out.println("strCell0===============:"+strCell);
         

          break;
        case 1://String
          strCell = aCell.getStringCellValue();

          System.out.println("strCell1¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥:"+strCell);
         

          break;
        default:
        System.out.println("格式不对不读");//其它格式的数据
        }

        }

      }
      }

    }

    }

  }

  } catch (Exception e) {
  System.out.println("ReadExcelError" + e);
  }

}


public static void main(String[] args) throws SQLException {
  
 String str = "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?";
 String sr[] = str.split(",");

 

//计算‘?’的个数,并打印显示
 for(int i=0 ; i<sr.length; i++){
  System.out.print(i+"  ");
 }
 
   System.out.println("  ");
   //用来获得从Ecxel中向PreparedStatement中传值的方法类
   MethodsToTables ms = new MethodsToTables();
   //用来获得不同表的插入数据库的sql语句的类
   InsertInToOracleSqls insql =new InsertInToOracleSqls();
   //用来获得表名的类
   JNNQTableNames tbs = new JNNQTableNames();
  

   try {
  //1. 连接Oracle 8/8i/9i的驱动程序:
  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();    
     //2. 建立连接:
  Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.30.150:1521:orcl","JNNQ","JNNQ");
        //
  Statement sm=conn.createStatement();
  String sql = "";
  String tableName = "";
  //String sql="insert into nq_schedule_info names(REPORT_ID,REPORT_CODE,TBY,TBR, COMMENTT)values (?,?,?,?,?)";
  //seq_product.nextval
  //String sql="insert into nq_schedule_info values (nq_schedule_info_sequence.nextval,?,?,?,?,?)";

  //----------1.插入nq_schedule_info
  
    

  //获得所要插入数据库中表的名称
  //----------2.enterprise_info
  // tableName = tbs.enterprise_info;

 

  //----- ----3.nq_crops_info
  //tableName = tbs.nq_crops_info;
   
  //----------4
  //tableName = tbs.nq_report_crops;
    
  //----------5
  //tableName = tbs.nq_report_target;
    
  //----------6
  //tableName = tbs.nq_reportfill_state;
  
  //----------7  nq_target_info
  //tableName = tbs.nq_target_info;
   
  //---------8
  //tableName = tbs.nq_zw_raq_table;
  
  //---------9
  //tableName = tbs.rd_nsi_day;
  
  //========10
  //tableName = tbs.report_directory;
  
  
  //========11
  tableName = tbs.qnnzwclyj;
  

  //根据表名获得sql 语句
  sql = insql.getInsertSqlForOracle(tableName); 
  System.out.println(sql);
  PreparedStatement pst=conn.prepareStatement(sql);
    //将被表示成1.3922433397E10的手机号转化为13922433397,不一定是最好的转换方法
    DecimalFormat df = new DecimalFormat("#");
    System.out.println("!fff");
    try {
     System.out.println("!2fff");
    // 创建对Excel工作簿文件的引用
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
      fileToBeRead)); 
    //System.out
    //  .println("===SheetsNum===" + workbook.getNumberOfSheets());//获取sheet数
    for (int numSheets = 0; numSheets < workbook.getNumberOfSheets(); numSheets++) {
      if (null != workbook.getSheetAt(numSheets)) {
      HSSFSheet aSheet = workbook.getSheetAt(numSheets);//获得一个sheet
 
      //System.out.println("+++getFirstRowNum+++" +
      // aSheet.getFirstRowNum());//
      //System.out.println("+++getLastRowNum+++" +
      // aSheet.getLastRowNum());

//      int p1=0,p4 = 0,p3=0,p0 = 0;

     System.out.println("!!!!!");

 

      //获得相应表的插入数据的的方法
      //ms.setENTERPRISE_INFOTableValues(conn, pst, aSheet, df);
      //ms.setNQ_CROPS_INFOTableValues(conn, pst, aSheet, df);
      //ms.setNQ_REPORT_CROPSTableValues(conn, pst, aSheet, df);
      //ms.setNQ_REPORT_TARGETTableValues(conn, pst, aSheet, df);
      //ms.setNQ_REPORTFILL_STATETableValues(conn, pst, aSheet, df);
      //ms.setNQ_TARGET_INFOTableValues(conn, pst, aSheet, df);
      //ms.setNQ_ZW_RAQ_TABLETableValues(conn, pst, aSheet, df);
      //ms.setRD_NSI_DAYTableValues(conn, pst, aSheet, df);
      //ms.setREPORT_DIRECTORYTableValues(conn, pst, aSheet, df);
      ms.setQNNZWCLYJTableValues(conn, pst, aSheet, df);
      }

    }

    } catch (Exception e) {
     System.out.println("????????");
    System.out.println("ReadExcelError" + e);
    }
  
  ResultSet rs=sm.executeQuery(sql);
  while (rs.next())
  {
   //对结果的处理
  }
  rs.close();
  pst.close();
  sm.close();
  conn.close();
 
   } catch (InstantiationException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (IllegalAccessException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (ClassNotFoundException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }

   exlFile poi = new exlFile();
  //poi.CreateExcel();
  poi.readExcel();

}
}

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics