2013-05-02 27 views
2

我已閱讀從Java程序here,herehere使用Sqoop的問題。Sqoop從一個Java程序內

我想出了下面,但我通過一個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 that this is HDFS path, rather than 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); 
    } 
} 

我相信,所有的罐子被正確包括和我已經測試到我的數據庫服務器的連接,以及工作原理好。

確切的錯誤是:

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.driver 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at SqoopExample.main(SqoopExample.java:14) 

不知道我做錯了。

+1

你有MySQL驅動'jar'在你的lib庫中? – 2013-05-02 19:50:16

+0

@MohammadAdil我的類路徑上有'mysql-connector-java-5.1.25-bin.jar'。 – tchakravarty 2013-05-02 19:51:42

回答

1

我相信,MySQL JDBC驅動程序類的正確名稱是:

com.mysql.jdbc.Driver

(在「駕駛提示資本 「d」)