Sparksql using JDBC code to access thrift JDBC Server

Source: Internet
Author: User

Start Thriftjdbcserver:

CD $SPARK _home/sbinstart-thriftserver. SH &

To access the Thriftjdbcserver code snippet using JDBC:

 PackageCom.luogankun.spark.sqlImportJava.sql.DriverManagerImportjava.sql.ConnectionImportjava.sql.PreparedStatement/*** JDBC Code access thrift JDBC Server *@authorLuogankun*/Object Jdbcthriftserver {def main (args:array[string]) {Class.forName ("Org.apache.hive.jdbc.HiveDriver") Val Conn= Drivermanager.getconnection ("Jdbc:hive2://hadoop000:10000/default", "Hadoop", "" ") Val PStat= Conn.preparestatement ("Select Track_time, URL, session_id, Referer, IP, end_user_id, city_id from Page_views WHERE city_ id = -1000 Limit 10 ") Val Rs=pstat.executequery () while(Rs.next ()) {println ("Track_time:" + rs.getstring ("Track_time")        + ", url:" + rs.getstring ("url")        + ", session_id:" + rs.getstring ("session_id")        + ", Referer:" + rs.getstring ("Referer")        + ", IP:" + rs.getstring ("IP"))        + ", end_user_id:" + rs.getstring ("end_user_id")        + ", city_id:" + rs.getstring ("city_id") } rs.close () Pstat.close () Conn.close ()}}

Sparksql using JDBC code to access thrift JDBC Server

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.