In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Package org.conan.myhadoop.mr;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class HiveJDBCConnection {private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; / / Hive after version 0.11.0 org.apache.hive.jdbc.HiveDriver private static String url = "jdbc:hive://localhost:10000/default" / Hive version 0.11.0 and later jdbc:hive2://localhost:10000/default private static String userName = "; private static String passWord ="; public static void main (String [] args) {try {Class.forName (driverName); Connection con = DriverManager.getConnection ("url", "userName", "passWord"); Statement stmt = con.createStatement () / / if it exists, delete String tableName = "jdbc_table"; String sql = "drop table if exists" + tableName; stmt.execute (sql) / / create table sql = "create table" + tableName + "(key string,value string) row format delimited fields terminated by', 'stored as textfile"; stmt.execute (sql); / / load data String Path= "/ home/hive_1.txt" Sql = "load data local inpath'" + Path+ "'into table" + tableName; stmt.execute (sql); / / query data sql = "select * from" + tableName; ResultSet res = stmt.executeQuery (sql); while (res.next ()) {System.out.println (res.getString (1) + "\ t" + res.getString (1)) } catch (ClassNotFoundException e) {System.out.println ("driver class not found"); e.printStackTrace ();} catch (SQLException e) {System.out.println ("there is a problem connecting Hive information"); e.printStackTrace ();}
The above is to connect HiveServer with Java, but HiveServer itself has many problems (such as security, concurrency, etc.). To solve these problems, the Hive0.11.0 version provides a new service: HiveServer2, which is a good solution to the security and concurrency problems of HiveServer.
The userName and passWord above are the username and password of the hive metadata mysql
Use Cases: Hive CLI versus Beeline
The following section focuses on the common uses of Hive CLI/HiveServer1 and how you can migrate to Beeline/HiveServer2 in each case.
Http://blog.cloudera.com/blog/2014/02/migrating-from-hive-cli-to-beeline-a-primer/?utm_source=tuicool&utm_medium=referral
Reference article:
Http://www.iteblog.com/archives/846
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.