1,pom中引入
<dependency>
<groupId>org.apache.calcite.avatica</groupId>
<artifactId>avatica-core</artifactId>
<version>1.15.0</version>
</dependency>
2,
public class DruidJdbcUtil {
public static AvaticaConnection connection() throws SQLException{
String urlStr = "jdbc:avatica:remote:url="【http://ip:8082】/druid/v2/sql/avatica/";
Properties connectionProperties = new Properties();
AvaticaConnection connection = DriverManager.getConnection(urlStr, connectionProperties);
AvaticaStatement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
String aa = resultSet.getString("aaa);
......
}
}
}
使用Druid与Calcite实现SQL查询

本文介绍如何在项目中使用Druid连接池与Apache Calcite的Avatica核心库,实现远程SQL查询功能。首先,需要在Maven的pom文件中引入Avatica依赖。接着,通过DruidJdbcUtil类的静态方法connection()建立数据库连接,并创建AvaticaStatement执行SQL语句,最后解析ResultSet获取查询结果。
2629

被折叠的 条评论
为什么被折叠?



