Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Apr 3, 2023
1 parent 48bf216 commit 00af58e
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions docs/quick_start/quick_start_with_jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The driver is available from Maven Central:
</dependency>
```

## U## Connect to non-kerberized Kyuubi Server
## Connect to non-kerberized Kyuubi Server

The below java code is using a keytab file to login and connect to Kyuubi server by JDBC.

Expand All @@ -44,47 +44,53 @@ import java.sql.*;

public class KyuubiJDBC {

private static String driverName = "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
private static String kyuubiJdbcUrl = "jdbc:kyuubi://localhost:10009/default;";
private static String driverName = "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
private static String kyuubiJdbcUrl = "jdbc:kyuubi://localhost:10009/default;";

public static void main(String[] args) throws SQLException {
Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
Statement stmt = conn.createStatement();
ResultSet rs = st.executeQuery("show databases");
while (rs.next()) {
public static void main(String[] args) throws SQLException {
try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl)) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = st.executeQuery("show databases")) {
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
}
}
}
}
}
}
```

## Connect to Kerberized Kyuubi Server

The following Java code is using a keytab file to login and connect to Kyuubi Server by JDBC.

```java
package org.apache.kyuubi.examples;

import java.sql.*;

public class KyuubiJDBCDemo {
private static String driverName = "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
private static String kyuubiJdbcUrlTemplate = "jdbc:kyuubi://localhost:10009/default;" +
"clientPrincipal=%s;clientKeytab=%s;serverPrincipal=%s";
public static void main(String[] args) throws SQLException {
String clientPrincipal = args[0]; // Kerberos principal
String clientKeytab = args[1]; // Keytab file location
String serverPrincipal = arg[2]; // Kerberos principal used by Kyuubi Server
String kyuubiJdbcUrl = String.format(kyuubiJdbcUrl, clientPrincipal, clientKeytab, serverPrincipal);
Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
Statement stmt = conn.createStatement();
ResultSet rs = st.executeQuery("show databases");
while (rs.next()) {

private static String driverName = "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
private static String kyuubiJdbcUrlTemplate = "jdbc:kyuubi://localhost:10009/default;" +
"clientPrincipal=%s;clientKeytab=%s;serverPrincipal=%s";

public static void main(String[] args) throws SQLException {
String clientPrincipal = args[0]; // Kerberos principal
String clientKeytab = args[1]; // Keytab file location
String serverPrincipal = arg[2]; // Kerberos principal used by Kyuubi Server
String kyuubiJdbcUrl = String.format(kyuubiJdbcUrl, clientPrincipal, clientKeytab, serverPrincipal);
try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl)) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = st.executeQuery("show databases")) {
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
rs.close();
stmt.close();
conn.close();
}
}
}
}
```

0 comments on commit 00af58e

Please sign in to comment.