2014-02-11 52 views
0

您好我正在嘗試DbCountPageView Hadoop給出的例子,首先我運行代碼只是沒有通過參數,它給了我一些數據庫訪問頁面的信息。之後我試圖運行這個程序給arguements,但它給了我下面的錯誤在日食:正在運行Hadoop DbCountPageView.java

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'testdb,root,' 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.Util.getInstance(Util.java:386) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928) 
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750) 
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290) 
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493) 
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526) 
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311) 
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) 
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) 
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347) 
    at java.sql.DriverManager.getConnection(Unknown Source) 
    at java.sql.DriverManager.getConnection(Unknown Source) 
    at org.apache.hadoop.examples.DBCountPageView.createConnection(DBCountPageView.java:102) 
    at org.apache.hadoop.examples.DBCountPageView.initialize(DBCountPageView.java:131) 
    at org.apache.hadoop.examples.DBCountPageView.run(DBCountPageView.java:394) 
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65) 
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:79) 
    at org.apache.hadoop.examples.DBCountPageView.main(DBCountPageView.java:432) 

我到Eclipse arguements是「com.mysql.jdbc.Driver」爲「jdbc:mysql的://本地主機: 3306/testDb「,」root「,」「 爲mysql數據庫。什麼是我不知道的錯誤,它給我訪問被拒絕的錯誤,我沒有把密碼到MySQL服務器。請幫助。

這是一個在hadoop安裝包中可用的大型程序:src-> examples-> org/apache/hadoop/example。

其中arguement應通過代碼如下

public int run(String[] args) throws Exception { 

    String driverClassName = DRIVER_CLASS; 
    String url = DB_URL; 

    if(args.length > 1) { 
     driverClassName = args[0]; 
     url = args[1]+","+"root"+","+""; 
    } 

    initialize(driverClassName, url); 

    JobConf job = new JobConf(getConf(), DBCountPageView.class); 

    job.setJobName("Count Pageviews of URLs"); 

    job.setMapperClass(PageviewMapper.class); 
    job.setCombinerClass(LongSumReducer.class); 
    job.setReducerClass(PageviewReducer.class); 

    DBConfiguration.configureDB(job, driverClassName, url); 

    DBInputFormat.setInput(job, AccessRecord.class, "Access" 
     , null, "url", AccessFieldNames); 

    DBOutputFormat.setOutput(job, "Pageview", PageviewFieldNames); 

    job.setMapOutputKeyClass(Text.class); 
    job.setMapOutputValueClass(LongWritable.class); 

    job.setOutputKeyClass(PageviewRecord.class); 
    job.setOutputValueClass(NullWritable.class); 

    try { 
     JobClient.runJob(job); 

     boolean correct = verify(); 
     if(!correct) { 
     throw new RuntimeException("Evaluation was not correct!"); 
     } 
    } finally { 
     shutdown();  
    } 
    return 0; 
    } 

    public static void main(String[] args) throws Exception { 

    int ret = ToolRunner.run(new DBCountPageView(), args); 
    System.exit(ret); 
    } 
+0

請準確提供將這些參數傳遞給jdbc的代碼。 – vefthym

+0

@vefthym我編輯了我的問題,請看看它。 –

回答

1

的問題是,你通過憑證在錯誤的地方。 請嘗試使用此代碼:

public int run(String[] args) throws Exception { 

    String driverClassName = DRIVER_CLASS; 
    String url = DB_URL; 

    if(args.length > 1) { 
     driverClassName = args[0]; 
     url = args[1]; 
    } 

    initialize(driverClassName, url); 

    JobConf job = new JobConf(getConf(), DBCountPageView.class); 

    job.setJobName("Count Pageviews of URLs"); 

    job.setMapperClass(PageviewMapper.class); 
    job.setCombinerClass(LongSumReducer.class); 
    job.setReducerClass(PageviewReducer.class); 

    DBConfiguration.configureDB(job, driverClassName, url, "root", ""); 

    DBInputFormat.setInput(job, AccessRecord.class, "Access" 
    , null, "url", AccessFieldNames); 

    DBOutputFormat.setOutput(job, "Pageview", PageviewFieldNames); 

    job.setMapOutputKeyClass(Text.class); 
    job.setMapOutputValueClass(LongWritable.class); 

    job.setOutputKeyClass(PageviewRecord.class); 
    job.setOutputValueClass(NullWritable.class); 

    try { 
     JobClient.runJob(job); 

     boolean correct = verify(); 
     if(!correct) { 
     throw new RuntimeException("Evaluation was not correct!"); 
     } 
    } finally { 
     shutdown();  
    } 
    return 0; 
} 

public static void main(String[] args) throws Exception { 
    int ret = ToolRunner.run(new DBCountPageView(), args); 
    System.exit(ret); 
} 
+0

好的,thnks它的工作。 –

相關問題