this.name = m_name;
this.age = m_age;
}
@Override
public void readFields(DataInput in) throws
IOException {
this.name = Text.readString(in);
this.age = in.readDouble();
}
@Override
public void write(DataOutput out) throws IOException {
Text.writeString(out, this.name);
out.writeDouble(age);
}
@Override
public void readFields(ResultSet resultSet) throws
SQLException {
this.name = resultSet.getString(1);
this.age = resultSet.getDouble(2);
}
@Override
public void write(PreparedStatement statement) throws SQLException {
statement.setString(1, this.name);
statement.setDouble(2, this.age);
}
}
public static void main(String[] args) throws Exception
{
String driverClassName = DRIVER_CLASS;
String url = DB_URL;
String dbuser=DB_USER;
String dbpw=DB_PASSWD;
//map-reduce设置
// JobConf job = new JobConf(getConf(), WordCountDB.class); //????存疑getConf是干什么的
JobConf job = new JobConf(WordCountDB.class);
job.setJobName("Count from DB");
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setInputFormat(DBInputFormat.class);
DBConfiguration.configureDB(job, driverClassName, url,dbuser,dbpw); //连接数据库
DBInputFormat.setInput(job, TeacherRecord.class, "teacher", null, "name", FieldNames);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(DoubleWritable.class);
DBOutputFormat.setOutput(job, "teacher", FieldNames);
job.setOutputKeyClass(TeacherRecord.class);
job.setOutputValueClass(NullWritable.class);
try
{
JobClient.runJob(job);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("运行出现异常");
}
}
错误如下:
java.lang.RuntimeException: Error in configuring object
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:93)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:64)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:117)
at org.apache.hadoop.mapred.JobConf.getInputFormat(JobConf.java:400)
at org.apache.hadoop.mapred.JobClient.writeOldSplits(JobClient.java:810)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:781)
at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:730)
at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1249)
at WordCountDB.main(WordCountDB.java:205)
纠结了好久,希望大家能帮帮忙,谢谢!
------解决方案--------------------------------------------------------帮顶吧,这代码太长了,恐怕会吓走不少人
------解决方案--------------------------------------------------------饿滴神啊!
------解决方案--------------------------------------------------------不错,观摩中
------解决方案--------------------------------------------------------
这里已经说出位置了,WordCountDB.main(WordCountDB.java:205)
自己检查下这一行
------解决方案--------------------------------------------------------
WordCountDB.java:205
对象属性是不是设错了?看看api