mysql - Sqoop from within a Java program -
i have read questions on using sqoop within java program here, here , here.
i came following, stumped classnotfoundexception:
import org.apache.hadoop.conf.configuration; import org.apache.hadoop.fs.*; import com.cloudera.sqoop.sqoopoptions; import com.cloudera.sqoop.sqoopoptions.filelayout; import com.mysql.jdbc.*; public class sqoopexample { public static void main(string[] args) throws exception { string driver = "com.mysql.jdbc.driver"; class.forname(driver); configuration config = new configuration(); // note hdfs path, rather core path config.addresource(new path("./config/core-site.xml")); config.addresource(new path("./config/hdfs-site.xml")); filesystem dfs = filesystem.get(config); sqoopoptions options = new sqoopoptions(); options.setdriverclassname(driver); options.setconnectstring("jdbc:mysql://localhost:3306/dbname"); options.settablename("v_webstats"); options.setusername("root"); options.setnummappers(1); options.settargetdir(dfs.getworkingdirectory()+"/testdirectory"); options.setfilelayout(filelayout.textfile); new com.cloudera.sqoop.tool.importtool().run(options); } }
i sure jars correctly included , have tested connection database server , works well.
the exact error is:
exception in thread "main" java.lang.classnotfoundexception: com.mysql.jdbc.driver @ java.net.urlclassloader$1.run(unknown source) @ java.net.urlclassloader$1.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ java.lang.class.forname0(native method) @ java.lang.class.forname(unknown source) @ sqoopexample.main(sqoopexample.java:14)
not sure doing wrong.
i believe proper name of mysql jdbc driver class is:
com.mysql.jdbc.driver
(notice capital "d" in "driver)
Comments
Post a Comment