In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Hive is the basic component for data warehouse applications in big data's technology cluster, and it is also the benchmark for other similar data warehouse applications. Basic data operations can be handled in hive-client through scripting. If you need to develop an application, you need to use the jdbc driver of hive to connect.
Code connection to hive requires starting metastore and hiveserver2 of hive first.
Hive-service metastore & hive-service hiveserver2 &
The configuration of hive-site.xml is:
Javax.jdo.option.ConnectionURLjdbc:mysql://192.168.174.131:3306/hive?createDatabaseIfNotExist=trueJDBC connect string for a JDBC metastorejavax.jdo.option.ConnectionDriverNamecom.mysql.jdbc.DriverDriver class name for a JDBC metastorejavax.jdo.option.ConnectionUserNamerootusername to use against metastore databasejavax.jdo.option.ConnectionPassword123456password to use against metastore database hive.metastore.uris thrift://192.168.174.131:9083 hive.support.sql11.reserved.keywordsfalse
The code needs to add two dependencies to connect to the hive:
Org.apache.hive hive-jdbc 1.2.1 org.apache.hadoop hadoop-common 2.6.4
Code demonstration:
Package com.fwmagic.jdbc;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import com.mysql.jdbc.Statement;public class JdbcHive {private static Connection conn; private static Statement st; public static void main (String [] args) throws Exception {Connection connection = getConnection (); System.out.println ("connection:" + connection); String sql = "show tables"; PreparedStatement prepareStatement = connection.prepareStatement (sql) ResultSet rs = prepareStatement.executeQuery (); while (rs.next ()) {String db = rs.getString (1); System.out.println (db);}} / * get database connection function * / private static Connection getConnection () {Connection con = null / / create a Connection object try {Class.forName ("org.apache.hive.jdbc.HiveDriver") to connect to the database; / / load the hive2 data driver con = DriverManager.getConnection ("jdbc:hive2://192.168.174.131:10000/default", "root", null) / / create a data connection} catch (Exception e) {System.out.println ("hive database connection failed" + e.getMessage ());} return con; / / return the established database connection}}
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.