码迷,mamicode.com
首页 > 数据库 > 详细

jdbc连接Apache druid

时间:2021-01-11 10:37:33      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:system   content   oid   exce   char   use   except   dep   rem   

//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);

    }
}

 

jdbc连接Apache druid

标签:system   content   oid   exce   char   use   except   dep   rem   

原文地址:https://www.cnblogs.com/wangbin2188/p/14247540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!