Jdbc connection hive0.14

Source: Internet
Author: User
The latest version of Jdbc connection hive0.14 is hive0.13. To download the latest hive, go to git to clone it. Hive0.14 supports direct insertion. Now we will provide an example of jdbc connection to hive0.14. Required jar package: tool class of the database, which is defined as non-inherited and private access * publicfinalclassD

The latest version of Jdbc connection hive0.14 is hive0.13. To download the latest hive, go to git to clone it. Hive0.14 supports direct insertion. Now we will provide an example of jdbc connection to hive0.14. Required jar package: tool class of the database, which is defined as non-inherited and private access */public final class D

Jdbc connection to hive0.14

The latest version on the official website is hive0.13. To download the latest hive, go to git to clone it.

Hive0.14 supports direct insertion.

Now we will provide an example of jdbc connection to hive0.14.

Jar package:

Database tool class, defined as non-inherited and private access

*/

Public final class DBTool {

Final private static String OPTION_FILE_NAME = "hivedatabase ";

Private static Connection conn;

Static ResourceBundle res;

Static {

Res = ResourceBundle. getBundle (OPTION_FILE_NAME );

Try {

String driver = res. getString ("jdbc. driver ");

Class. forName (driver );

} Catch (ClassNotFoundException e ){

E. printStackTrace ();

Throw new RuntimeException (e );

}

}

/**

* Obtain the database connection

*

* @ Return conn

*/

Public static Connection getConnection (){

If (null = conn ){

Try {

String url = res. getString ("jdbc. url ");

String user = res. getString ("jdbc. username ");

String password = res. getString ("jdbc. password ");

Conn = DriverManager. getConnection (url, user, password );

} Catch (SQLException e ){

E. printStackTrace ();

Throw new RuntimeException (e );

}

}

Return conn;

}

/**

* Release resources

*

* @ Param conn

* @ Param pstmt

* @ Param rs

*/

Public static void closeJDBC (Connection conn, PreparedStatement pstmt,

ResultSet rs ){

If (null! = Rs ){

Try {

Rs. close ();

} Catch (SQLException e ){

E. printStackTrace ();

Throw new RuntimeException (e );

} Finally {

If (null! = Pstmt ){

Try {

Pstmt. close ();

} Catch (SQLException e ){

E. printStackTrace ();

Throw new RuntimeException (e );

} Finally {

If (null! = Conn ){

Try {

Conn. close ();

} Catch (SQLException e ){

E. printStackTrace ();

Throw new RuntimeException (e );

}

}

}

}

}

}

}

}

2. hivedatabase. properties

# Hive database setting

Jdbc. type = hive

Jdbc. driver = org. apache. hive. jdbc. HiveDriver

Jdbc. url = jdbc: hive2: // 192.168.2.150: 10000/default

Jdbc. username = hadoop

Jdbc. password =

3. test is a class.

Public class Test {

Public static void main (String [] args) throws Exception {

Connection connection = DBTool. getConnection ();

System. out. println (connection );}

}

If the connection is successful, you have successfully connected to hive.

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.