????????????????hadoop????????????????????????е??????????????hadoop??????????ü???????????????????дС????????????????????ú??????????????????????????????????????????и???????????
?????????????????????????????????hadoop????????mysql?????????е?????????????????д????????????????????????????????????????????????????????hadoop????????????????飬???????HA????????????????η?????????????????????????????鶼????????????????д????????...
????StudentRecord??:
package com.simope.mr.db;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;
public class StudentRecord implements Writable?? DBWritable{
int id;
String name;
int age;
int departmentID;
@Override
public void readFields(DataInput in) throws IOException {
this.id = in.readInt();
this.name = Text.readString(in);
this.age = in.readInt();
this.departmentID = in.readInt();
}
@Override
public void write(DataOutput out) throws IOException {
out.write(this.id);
Text.writeString(out?? this.name);
out.write(this.age);
out.write(this.departmentID);
}
public void readFields(ResultSet rs) throws SQLException {
this.id = rs.getInt(1);
this.name = rs.getString(2);
this.age = rs.getInt(3);
this.departmentID = rs.getInt(4);
}
public void write(PreparedStatement ps) throws SQLException {
ps.setInt(1?? this.id);
ps.setString(2?? this.name);
ps.setInt(3?? this.age);
ps.setInt(4?? this.departmentID);
}
@Override
public String toString() {
return new String(this.name + " " + this.age + " " + this.departmentID);
}
}
????TeacherRecord??:
package com.simope.mr.db;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;
public class TeacherRecord implements Writable?? DBWritable{
int id;
String name;
int age;
int departmentID;
@Override
public void readFields(DataInput in) throws IOException {
this.id = in.readInt();
this.name = Text.readString(in);
this.age = in.readInt();
this.departmentID = in.readInt();
}
@Override
public void write(DataOutput out) throws IOException {
out.write(this.id);
Text.writeString(out?? this.name);
out.write(this.age);
out.write(this.departmentID);
}
public void readFields(ResultSet rs) throws SQLException {
this.id = rs.getInt(1);
this.name = rs.getString(2);
this.age = rs.getInt(3);
this.departmentID = rs.getInt(4);
}
public void write(PreparedStatement ps) throws SQLException {
ps.setInt(1?? this.id);
ps.setString(2?? this.name);
ps.setInt(3?? this.age);
ps.setInt(4?? this.departmentID);
}
@Override
public String toString() {
return new String(this.name + " " + this.age + " " + this.departmentID);
}
}