Hive jdbc--Learning hive in layman's

Source: Internet
Author: User
Tags connection pooling stmt

Part I: Building a hive JDBC development environment

Build:Steps ? New project Hivetest? Import hive-dependent packages? Hive Command line start thrift service? Hive--service Hiveserver &Part Two: Introduction of basic Operation ObjectsConnectionDescription: The connection object connected to hive? The connection to Hive? jdbc:hive://ip:10000/default "? Get the Connection method? Drivermanager.getconnection ("Jdbc:hive://ip:10000/default", "", "" ");Statement? Description: Used to execute statements? How to create a method? Statement stmt = Con.createstatement ();? The Main method? Executequery?executeResultSet? Description: Used to store the result set? How do I create a method? Stmt.executequery method to get the Main method? GetString ()special types of processing? Array? Map? StructPart III: A simple examplebackgroundWiththe advent of the 3G era, the choice of a variety of mobile terminals to the Internet more and more people, such as mobile phones, tablets, etc., which contains a huge business opportunities, because the terminal can be directly accurate to people. So the analysis of the user log on the Internet, also become a new hotspot, these in the database age is unthinkable, because the data scale is huge, cloud computing solves this problemRequirements DescriptionAnalyze the user's mobile internet logs to get Mobile phone traffic statistics information and statistics based on the terminal to obtain trafficTable Planning? Log Table Log? FieldUser mobile number, terminal type, access URL, Access start time, Access end time, access traffic phone string, client_type string, url string,visit_begintime timestamp,vis It_endtime timestamp,traffic bigint? Data Files? data is separated by \ t, and rows are separated by \ n? data example: 13154587453 andorid www.baidu.com 2011-09-01 17:30:08 2011-09-01 17:31:09 10? According to file location:/home/test/log.txt? cell phone number belongs to phone_location? FieldUser mobile phone number, attribution phone string, location stirng? Data FilesData is delimited by \ t between rows, example of data separated by \ n: 1334567890 Chaoyang data File location:/home/test/phone_local.txt? Mobile Traffic Statistics Total_traffic_by_phone? FieldMobile number, total traffic (k), attribution, total access time (seconds) phone string,totol_traffic bigint,area string,visit_total_time timestamp? Data Files data between the \ t delimited, between rows to \ n DelimitedData example: 13154587453 102 Chaoyang 123? Terminal type Statistics Total_traffic_by_client_type? FieldTerminal type, access total traffic (k) Client_type string,totoal_traffic bigint? Data Files data between the \ t delimited, between rows to \ n DelimitedData example: Andorid 1034implementation Steps? initialize data, table? Example: Create External Table phone_location (phone String,area string) row format delimited fields terminated by ' \ t ' Lines terminated by ' \ n ' stored as textfile? Writing processing logicJava code exampletry {Class.forName (drivername);Connection con = drivermanager.getconnection ("Jdbc:hive://ip:10000/default", "", "" ");Statement stmt = Con.createstatement ();String sql = "Show tables";//Show TablesSystem.out.println ("Running:" + sql);ResultSet res = stmt.executequery (sql);if (Res.next ()) {System.out.println (res.getstring (1));}Part IV: Hive-based database connection pooling Implementation of database connection pool based on Hive? using DataSource as the data source implementation? Dbconnectionmanager use a singleton mode? Provides a way to get a connection, close a connection? Setupdatasource ()? Dbconnectionmanager getinstance ()? Close (Connection conn)? Synchronized Connection getconnection ()

Hive jdbc--Learning hive in layman's

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.