Java Operation Sqoop Object

Source: Internet
Author: User

Using the Eclipse tool to manipulate Sqoop1.4.6 objects under Windows

Sqoop is used to import and export data between a relational database and Hadoop, and you need to build a Hadoop development environment when using Eclipse tools under Windows

  1. Refer to Java Operation Pom.xml configuration for HDFs objects, add configuration

    <Dependency><Groupid>org.apache.sqoop</Groupid><Artifactid>sqoop</artifactid> < version>1.4.6</version></dependency> < dependency> <groupId>mysql< Span class= "Hljs-tag" ></groupid> < artifactid>mysql-connector-java</ artifactid> <version>5.1.36< Span class= "Hljs-tag" ></version></ dependency>            

    Using MySQL for import and export operations between data and Hadoop requires a MySQL driver package. Sqoop-1.4.6.jar package in maven download not down, the Sqoop in the installation directory $sqoop_home under the Sqoop-1.4.6.jar package copy to the MAVEN repository corresponding Sqoop directory.

  2. Environment variables for configuring Sqoop under Windows
    When operating sqoop under Windows, you need to use packages under Sqoop to configure environment variables.
    Extract the downloaded sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz to the native directory and configure the SQOOP environment variables:

    SQOOP_HOME=F:\data\sqoop-1.4.6.bin__hadoop-2.0.4-alphaPATH=PATH;%SQOOP_HOME%\bin; 
  3. Check if configuration is successful
    sqoop version

    Warning No tube, no configuration required under Windows

  4. Java Operation Sqoop Object
    Windows native under MySQL service to start first

    • 4.1 Importing MySQL data into HDFs

      Import org.apache.hadoop.conf.Configuration;Import Org.apache.sqoop.Sqoop;Import Org.apache.sqoop.tool.SqoopTool;Import Org.apache.sqoop.util.OptionsFileUtil;PublicClasssqooptest {PrivateStaticIntImportdatafrommysql ()Throws Exception {string[] args =New string[] {"--connect","Jdbc:mysql://192.168.1.97:3306/mydb","--driver","Com.mysql.jdbc.Driver","-username","Root","-password","Root","--table","User","-M","1", "--target-dir",  "Java_import_user"}; string[] expandarguments = optionsfileutil.expandarguments (args); Sqooptool tool = Sqooptool.gettool ( "import"); Configuration conf = new Configuration (); Conf.set (" hdfs://192.168.1.200:9000 "); //set HDFS service address configuration Loadplugins = sqooptool.loadplugins (conf); Sqoop Sqoop = new Sqoop ((com.cloudera.sqoop.tool.SqoopTool) tool, Loadplugins); return sqoop.runsqoop (Sqoop, expandarguments); } public static void main (string[] args) throws Exception {importdatafrommysql ();}}    

      The resulting file can be viewed on HDFs

      Found in HDFs generated directory/user/cyyun/java_import_user, the program --target-dir does not specify a specific path, the native Windows user name is Cyyun, on Windows on the use of program operations will be in/user/ The directory under which a Windows user name is generated
      View results:

      -cat /user/cyyun/java_import_user/part-m-00000hadoop fs -cat /user/cyyun/java_import_user/part-m-00001 

      --target-dirrun the view results as specified in the program /user/root/java_import_user :

      -cat /user/root/java_import_user/part-m-00000 

This article refers to:
http://blog.csdn.net/guzicheng/article/details/41519947

Java Operation Sqoop Object

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.