Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use "SqoopOptions" for executing sqoop in your Java Program.</p> <p>This is a sample code for importing a table in MySql to HDFS.</p> <pre><code>public static void importSQLToHDFS() throws Exception { String driver = "com.mysql.jdbc.Driver"; Class.forName(driver).newInstance(); Configuration config = new Configuration(); config.addResource(new Path("/.../conf/core-site.xml")); config.addResource(new Path("/.../conf/hdfs-site.xml")); properties.load(new FileInputStream("/.../sqoopimport.properties")); SqoopOptions options = new SqoopOptions(); options.setDriverClassName(driver); options.setHadoopHome("/.../hadoop-0.20.2-cdh3u2"); options.setConnectString(properties.getProperty("db_connection_string")); options.setTableName(properties.getProperty("db_mysql_table_name")); options.setUsername(properties.getProperty("db_usr_id")); options.setPassword(properties.getProperty("db_passwd")); options.setNumMappers(1); options.setTargetDir(properties.getProperty("path_export_file")); options.setFileLayout(FileLayout.TextFile); new ImportTool().run(options); } </code></pre> <p>For Exporting see sample code below. Note: Here property file is not used. Make sure you have created the table to which the data is to be imported.</p> <pre><code>public static boolean exportHDFSToSQL() throws InstantiationException, IllegalAccessException, ClassNotFoundException { try { SqoopOptions options=new SqoopOptions(); options.setConnectString("jdbc:mysql://localhost:3306/dbName"); options.setUsername("user_name"); options.setPassword("pwd"); options.setExportDir("path of file to be exported from hdfs"); options.setTableName("table_name"); options.setInputFieldsTerminatedBy(','); options.setNumMappers(1); new ExportTool().run(options); } catch (Exception e) { return false; } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload