0

我目前正在使用 Apache 的 MetaModel 4.6.0 API for Java 1.8。我无法获取要使用的 DataContext 的默认架构。下面是我的代码片段:

private DataContext dataContext;
private Schema schema;
private Table table;

/**
 * @brief Constructor that takes in an excel file
 * @detail Creates a schema for the excel file to be easily queried
 * @param excelFile 
 */
public ExcelQuery(File file)
{
    dataContext = new ExcelDataContext(file);
    schema = dataContext.getDefaultSchema();
    table = schema.getTables()[0];
}

当它到达这部分时:

schema = dataContext.getDefaultSchema();

代码只是挂起尝试执行此操作。任何想法为什么会发生这种情况?

我的目标是能够使用此 API 查询 excel 文件。我已经看到很多例子都这样做并且工作,但似乎无法重新创建它。

4

1 回答 1

0

正如你所说,DataContext.getDefaultSchema 不起作用尝试使用打印所有架构

Schema[] schema = dc.getSchemas();

然后尝试正确的 schemaName。

Schema schema = dc.getSchemaByName(schemaName);
于 2017-05-17T11:18:05.493 回答