通过Fillio API从excel检索数据,它会出错

时间:2017-05-26 05:55:40

标签: java jdbc apache-poi

package com.excel.reader;

import java.io.FileNotFoundException;
import com.codoid.products.exception.FilloException;
import com.codoid.products.fillo.Connection;
import com.codoid.products.fillo.Fillo;
import com.codoid.products.fillo.Recordset;

public class ReaderApi {

    public static void main(String[] args) throws FileNotFoundException {
        // TODO Auto-generated method stub

        try {

            Fillo fillo = new Fillo();
            Connection connection = fillo
                    .getConnection("E:\\Projects\\POC\\Documents\\Optima\\Docs\\Optima_Other.xlsx");
            String strQuery = "Select * from Optima_Data where Property='Holiday Inn Express London - Wandsworth'";
            Recordset recordset = connection.executeQuery(strQuery);
            while (recordset.next()) {
                System.out.println(recordset.getField("Rate"));
            }
        } catch (FilloException e) {
            System.out.println(e.getMessage());
        }
    }

}

在运行此代码时,它会在连接语句中给出以下异常。

   Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/impl/CTWorksheetImpl$1ColsList
at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl.getColsList(Unknown Source)
at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.cleanColumns(ColumnHelper.java:57)
at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.<init>(ColumnHelper.java:50)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:194)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:180)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:300)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:165)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:200)
at com.codoid.products.fillo.Fillo.getWorkbook(Fillo.java:59)
at com.codoid.products.fillo.Fillo.getConnection(Fillo.java:40)
at com.excel.reader.ReaderApi.main(ReaderApi.java:21)
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl$1ColsList
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more

我也尝试过使用JDBC:

package com.excel.reader;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ExcelDB {

public static void main(String[] args) {
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection conn = DriverManager
                .getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};"
                        + "Dbq=E:\\Projects\\POC\\Documents\\Optima\\Docs\\Optima_Data.xlsm;");

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT SN,IR FROM [Sheet1$]");

        if (rs != null) {
            while (rs.next()) {
                System.out.println(rs.getInt("AllTXN_Issued"));
            }
        }
        rs.close();

        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

这也为类找不到例外。

  1. excel的大小非常大,如包含许多列和表的75000-100000条记录。我必须从中获取数据并与UI进行比较。

  2. 我还尝试使用Apache POI来检索数据,但是存储大量数据并处理它以获得预期值似乎也很困难。

  3. 注意:有没有更好的方法呢?请建议。

1 个答案:

答案 0 :(得分:0)

我认为这与某些java版本控制或Eclipse配置问题有关。所以关闭这个问题。