0

我正在使用托管在 tomcat 上的第三方应用程序,它只允许 jdbc 连接来查询数据库。在新的数据源配置向导中,我插入了以下详细信息

URL: jdbc:calcite:model=/someLocation/jdbcConnectionModel.json

Driver: org.apache.calcite.jdbc.Driver

/someLocation/jdbcConnectionModel.json 内容:

inline:
{
  version: '1.0',
  schemas: [
     {
       type: 'custom',
       name: 'TEST',
       factory: 'org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory',
       operand: {
         locatorHost: 'serverUrl', 
         locatorPort: '10150', 
         regions: 'testRegion', 
         pdxSerializablePackagePath: 'org.apache.calcite.adapter.geode.domain.*' 
       }
     }
   ]
}

我在应用程序可以访问的tomcat的lib文件夹中复制了以下jar:

calcite-geode-1.17.0.jar
calcite-core-1.17.0.jar
commons-compiler-jdk-3.0.9.jar

但它给出了一个错误:

测试连接时出错,请验证 DataSource 配置并重试:无法加载 JDBC 驱动程序类 'org.apache.calcite.jdbc.Driver'

有什么我想念的吗?

我已经尝试过使用java代码并且它有效:

public class RelationalJdbcExample {

final static String geodeModelJson =
        "inline:"
            + "{\n"
            + "  version: '1.0',\n"
            + "  schemas: [\n"
            + "     {\n"
            + "       type: 'custom',\n"
            + "       name: 'TEST',\n"
            + "       factory: 'org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory',\n"
            + "       operand: {\n"
            + "         locatorHost: 'serverUrl', \n"
            + "         locatorPort: '10150', \n"
            + "         regions: 'testRegion', \n"
            + "         pdxSerializablePackagePath: 'org.apache.calcite.adapter.geode.domain.*' \n"
            + "       }\n"
            + "     }\n"
            + "   ]\n"
            + "}";


public static Connection getGemfireConnection() throws ClassNotFoundException, SQLException{
    Class.forName("org.apache.calcite.jdbc.Driver");
    Properties info = new Properties();
    info.put("model", geodeModelJson);
    Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
    return connection;
}


public static void main(String[] args) {

    Statement statement;
    try {
         Connection connection = getGemfireConnection();
         CalciteConnection calciteConnection =
                    connection.unwrap(CalciteConnection.class);
        statement = calciteConnection.createStatement();
        String query= "SELECT \"a\".\"testAttr\" FROM \"TEST\".\"testRegion\" AS \"a\" ";
        ResultSet resultSet = statement.executeQuery(query);


        System.out.println("resultSet===="+resultSet);
        while (resultSet.next()) {
            ResultSetMetaData metaData = resultSet.getMetaData();
            System.out.println(metaData.toString());
        }
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }
}

}

上面的代码从缓存中获取数据并正确返回。请帮忙。

4

0 回答 0