(1) write scripts to install java into Linux OS with file jdk-7u71-Linux-x64.gz
ID: 3903567 • Letter: #
Question
(1) write scripts to install java into Linux OS with file jdk-7u71-Linux-x64.gz and a brief explanation.2)write scripts to install Hadoop into Linux OS with file Hadoop-2.4.1.tar.gz and give a brief explanation.
3)write scripts to run word counts of calculating example in Hadoop environment and give a brief explanation.
4) a SQL statement is “SELECT id, first, last,age FROM Employees”, write SQL scripts to create a table that can match this statement, then write a java program to execute this statement and give a brief explanation.
(1) write scripts to install java into Linux OS with file jdk-7u71-Linux-x64.gz and a brief explanation.
2)write scripts to install Hadoop into Linux OS with file Hadoop-2.4.1.tar.gz and give a brief explanation.
3)write scripts to run word counts of calculating example in Hadoop environment and give a brief explanation.
4) a SQL statement is “SELECT id, first, last,age FROM Employees”, write SQL scripts to create a table that can match this statement, then write a java program to execute this statement and give a brief explanation.
2)write scripts to install Hadoop into Linux OS with file Hadoop-2.4.1.tar.gz and give a brief explanation.
3)write scripts to run word counts of calculating example in Hadoop environment and give a brief explanation.
4) a SQL statement is “SELECT id, first, last,age FROM Employees”, write SQL scripts to create a table that can match this statement, then write a java program to execute this statement and give a brief explanation.
Explanation / Answer
3).write scripts to run word counts of calculating example in Hadoop environment and give a brief explanation
package com.bel;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.util.GenericOptionsParser;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
public class WordCount
{
static class MapForWordCount extends Mapper<LongWritable, Text, Text, IntWritable>
{
public void map(LongWritable key, Text value, Context con) throws IOException, InterruptedException
{
String line = value.toString();
String[] words=line.split(",");
for(String word: words )
{
Text outputKey = new Text(word.toUpperCase().trim());
IntWritable outputValue = new IntWritable(1);
con.write(outputKey, outputValue);
}
}
}
static class ReduceForWordCount extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text word, Iterable<IntWritable> values, Context con) throws IOException, InterruptedException
{
int sum = 0;
for(IntWritable value : values)
{
sum += value.get();
}
con.write(word, new IntWritable(sum));
}
}
public static void main(String [] args) throws Exception
{
Configuration c=new Configuration();
String[] files=new GenericOptionsParser(c,args).getRemainingArgs();
Path input=new Path(files[0]);
Path output=new Path(files[1]);
Job j=new Job(c,"WordCount");
j.setJarByClass(WordCount.class);
j.setMapperClass(MapForWordCount.class);
j.setReducerClass(ReduceForWordCount.class);
j.setOutputKeyClass(Text.class);
j.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(j, input);
FileOutputFormat.setOutputPath(j, output);
System.exit(j.waitForCompletion(true)?0:1);
}
}
We need To Follow Below steps to Excute the Above Program:-
-----------------------------------------------------------
1.Open Eclipse> File > New > Java Project >( Name it – MRProgramsDemo) > Finish
2.Right Click > New > Package ( Name it - PackageDemo) > Finish
3.Right Click on Package > New > Class (Name it - WordCount)
4.Add Following Reference Libraries
->Right Click on Project > Build Path> Add External Archivals
/usr/lib/hadoop-0.20/hadoop-core.jar
Usr/lib/hadoop-0.20/lib/Commons-cli-1.2.jar
4) a SQL statement is “SELECT id, first, last,age FROM Employees”, write SQL scripts to create a table that can match this statement, then write a java program to execute this statement and give a brief explanation.
//Inserting Records into Employee Table and Fetching Same Records from the Database.
package com.samples;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
public class JDBC_Customer
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
try
{
int cust_id;
String Name,Address;
System.out.println("--------------------------------");
System.out.println(" Recording customer Information");
System.out.println("Please Enter Cusomer id:");
cust_id=sc.nextInt();
System.out.println("Please Enter Customer Name");
Name=sc.next();
System.out.println(" Please Enter the Customer Address");
Address=sc.next();
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
System.out.println("plz wait.... Connecting with Database");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:venkanna","venky_user","venky");
//step3 create the statement object
Statement stmt=con.createStatement();
String sql = "INSERT INTO Employee " + "VALUES (cust_id, Name, Address)";
//step4 execute query
stmt.executeUpdate(sql);
System.out.println("Inserted records into the Employee Table");
//Fetching Records from the database
ResultSet rs=stmt.executeQuery("select * from Employee");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(2)+" "+rs.getString(3));
}
//step5 close the connection object
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Please Wait for Remaining Updates
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.