[root@172 ~]# su hadoop[hadoop@172 root]$ cd /usr/local/service/kyuubi
[hadoop@10kyuubi]$ bin/beeline -u "jdbc:hive2://${zkserverip1}:${zkport},${zkserverip2}:${zkport},${zkserverip3}:${zkport}/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi" -n hadoop
[hadoop@10kyuubi]$ bin/beeline -u "jdbc:hive2://${kyuubiserverip}:${kyuubiserverport}" -n hadoop
${zkserverip}:${zkport}
见 kyuubi-defaults.conf
的 kyuubi.ha.zookeeper.quorum
配置。
${kyuubiserverport}
见 kyuubi-defaults.conf
的 kyuubi.frontend.bind.port
配置。0: jdbc:hive2://ip:port> create database sparksql;+---------+| Result |+---------++---------+No rows selected (0.326 seconds)
0: jdbc:hive2://ip:port> use sparksql;+---------+| Result |+---------++---------+No rows selected (0.077 seconds)0: jdbc:hive2://ip:port> create table sparksql_test(a int,b string);+---------+| Result |+---------++---------+No rows selected (0.402 seconds)0: jdbc:hive2://ip:port> show tables;+-----------+----------------+--------------+| database | tableName | isTemporary |+-----------+----------------+--------------+| sparksql | sparksql_test | false |+-----------+----------------+--------------+1 row selected (0.108 seconds)
mvn archetype:generate -DgroupId=$yourgroupID -DartifactId=$yourartifactID -DarchetypeArtifactId=maven-archetype-quickstart
simple---pom.xml 核心配置,项目根下---src---main---java Java 源码目录---resources Java 配置文件目录---test---java 测试源码目录---resources 测试配置目录
<dependencies><dependency><groupId>org.apache.kyuubi</groupId><artifactId>kyuubi-hive-jdbc-shaded</artifactId><version>1.4.1-incubating</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><!-- keep consistent with the build hadoop version --><version>2.8.5</version></dependency></dependencies>
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><encoding>utf-8</encoding></configuration></plugin><plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build>
import java.sql.*;public class KyuubiJDBCTest {private static String driverName ="org.apache.kyuubi.jdbc.KyuubiHiveDriver";public static void main(String[] args)throws SQLException {try {Class.forName(driverName);} catch (ClassNotFoundException e) {e.printStackTrace();System.exit(1);}Connection con = DriverManager.getConnection("jdbc:hive2://$kyuubiserverhost:$kyuubiserverport/default", "hadoop", "");Statement stmt = con.createStatement();String tableName = "KyuubiTestByJava";stmt.execute("drop table if exists " + tableName);stmt.execute("create table " + tableName +" (key int, value string)");System.out.println("Create table success!");// show tablesString sql = "show tables '" + tableName + "'";System.out.println("Running: " + sql);ResultSet res = stmt.executeQuery(sql);if (res.next()) {System.out.println(res.getString(1));}// describe tablesql = "describe " + tableName;System.out.println("Running: " + sql);res = stmt.executeQuery(sql);while (res.next()) {System.out.println(res.getString(1) + "\\t" + res.getString(2));}sql = "insert into " + tableName + " values (42,\\"hello\\"),(48,\\"world\\")";stmt.execute(sql);sql = "select * from " + tableName;System.out.println("Running: " + sql);res = stmt.executeQuery(sql);while (res.next()) {System.out.println(String.valueOf(res.getInt(1)) + "\\t"+ res.getString(2));}sql = "select count(1) from " + tableName;System.out.println("Running: " + sql);res = stmt.executeQuery(sql);while (res.next()) {System.out.println(res.getString(1));}}}
mvn package
scp $localfile root@公网IP地址:/usr/local/service/kyuubi
[hadoop@172 kyuubi]$ yarn jar $package.jar KyuubiJDBCTest
Create table success!Running: show tables 'KyuubiTestByJava'defaultRunning: describe KyuubiTestByJavakey intvalue stringRunning: select * from KyuubiTestByJava42 hello48 worldRunning: select count(1) from KyuubiTestByJava2
本页内容是否解决了您的问题?