jdbc连接Apache druid


//jdbc连接druid
<
dependency> <groupId>org.apache.calcite.avatica</groupId> <artifactId>avatica-core</artifactId> <version>1.15.0</version> </dependency>
public class Test {
    public static void main(String[] args) throws SQLException {
        AvaticaConnection connection = connection();
        AvaticaStatement statement = connection.createStatement();
        String sql = "select userNo,count(1) as num  from collection_platform_report " +
                "group by userNo " +
                "limit 10";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            System.out.println(resultSet.getString("num"));
        }

    }

    public static AvaticaConnection connection() throws SQLException {
        String urlStr = "jdbc:avatica:remote:url=http://prod-node6:8888/druid/v2/sql/avatica/";
        Properties connectionProperties = new Properties();
        connectionProperties.put("Content-Type", "application/json; charset=utf-8");
        return (AvaticaConnection) DriverManager.getConnection(urlStr, connectionProperties);

    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM