{% highlight Groff markup %} jdbc:kylin://:/<kylin_project_name> {% endhighlight %}
{% highlight Groff markup %} Driver driver = (Driver) Class.forName(“org.apache.kylin.jdbc.Driver”).newInstance();
Properties info = new Properties(); info.put(“user”, “ADMIN”); info.put(“password”, “KYLIN”); Connection conn = driver.connect(“jdbc:kylin://localhost:7070/kylin_project_name”, info); Statement state = conn.createStatement(); ResultSet resultSet = state.executeQuery(“select * from test_table”);
while (resultSet.next()) { assertEquals(“foo”, resultSet.getString(1)); assertEquals(“bar”, resultSet.getString(2)); assertEquals(“tool”, resultSet.getString(3)); } {% endhighlight %}
{% highlight Groff markup %} Driver driver = (Driver) Class.forName(“org.apache.kylin.jdbc.Driver”).newInstance(); Properties info = new Properties(); info.put(“user”, “ADMIN”); info.put(“password”, “KYLIN”); Connection conn = driver.connect(“jdbc:kylin://localhost:7070/kylin_project_name”, info); PreparedStatement state = conn.prepareStatement(“select * from test_table where id=?”); state.setInt(1, 10); ResultSet resultSet = state.executeQuery();
while (resultSet.next()) { assertEquals(“foo”, resultSet.getString(1)); assertEquals(“bar”, resultSet.getString(2)); assertEquals(“tool”, resultSet.getString(3)); } {% endhighlight %}
Kylin jdbc driver支持元数据列表方法: 通过sql模式过滤器(比如 %)列出catalog、schema、table和column。
{% highlight Groff markup %} Driver driver = (Driver) Class.forName(“org.apache.kylin.jdbc.Driver”).newInstance(); Properties info = new Properties(); info.put(“user”, “ADMIN”); info.put(“password”, “KYLIN”); Connection conn = driver.connect(“jdbc:kylin://localhost:7070/kylin_project_name”, info); Statement state = conn.createStatement(); ResultSet resultSet = state.executeQuery(“select * from test_table”);
ResultSet tables = conn.getMetaData().getTables(null, null, “dummy”, null); while (tables.next()) { for (int i = 0; i < 10; i++) { assertEquals(“dummy”, tables.getString(i + 1)); } } {% endhighlight %}