gpt4 book ai didi

java - 运行 Hadoop DbCountPageView.java

转载 作者:行者123 更新时间:2023-11-29 13:14:09 24 4
gpt4 key购买 nike

嗨,我正在尝试 Hadoop 提供的 DbCountPageView 示例,首先我简单地运行代码而不传递参数,它给了我一些数据库访问页面信息。在我尝试运行这个程序给出争论后,但它在 Eclipse 中给了我以下错误:

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 的争论是“com.mysql.jdbc.Driver”“jdbc:mysql://localhost:3306/testDb”,“root”,“”对于mysql数据库。我不知道什么错误,它给了我访问被拒绝错误,我没有向 mysql 服务器输入密码。请帮忙。

它是一个大型程序,位于hadoop安装包中:src->examples->org/apache/hadoop/example。

争论应该通过的代码如下

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);
}

最佳答案

问题在于您将凭据传递到了错误的位置。请尝试使用以下代码:

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);
}

关于java - 运行 Hadoop DbCountPageView.java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com