Kylin JDBC使用案例

一、新建空的maven工程

二、在项目中导入依赖

<dependencies>
    <dependency>
        <groupId>org.apache.kylin</groupId>
        <artifactId>kylin-jdbc</artifactId>
        <version>3.0.2</version>
    </dependency>
</dependencies>

三、编写class

public class TestKylin {
    public static void main(String[] args) throws Exception {
        //Kylin_JDBC 驱动
        String KYLIN_DRIVER = "org.apache.kylin.jdbc.Driver";
        //Kylin_URL,最后是project的名字
        String KYLIN_URL = "jdbc:kylin://120.55.103.238:7070/project1";
        //Kylin的用户名
        String KYLIN_USER = "ADMIN";
        //Kylin的密码
        String KYLIN_PASSWD = "KYLIN";
        //添加驱动信息
        Class.forName(KYLIN_DRIVER);
        //获取连接
        Connection connection = DriverManager.getConnection(KYLIN_URL, KYLIN_USER, KYLIN_PASSWD);
        //预编译SQL
        PreparedStatement ps = connection.prepareStatement("SELECT * FROM KYLIN_SALES limit 10");
        //执行查询
        ResultSet resultSet = ps.executeQuery();
        //遍历打印
        while (resultSet.next()) {
            //几个字段写几个get 后面类型根据数据类型写
            System.out.print(resultSet.getInt(1)+"\t");
            System.out.print(resultSet.getDate(2)+"\t");
            System.out.println(resultSet.getString(3));
        }


    }
}

你可能感兴趣的:(Apache,Kylin,JDBC,Java,数据查询,数据库连接)