|
|
-
Re: Error while executing program with Hive JDBCAniket Mokashi 2012-04-26, 07:35
put libthrift and libfb303 jars on classpath.
Thanks, Aniket On Wed, Apr 25, 2012 at 11:14 PM, Bhavesh Shah <[EMAIL PROTECTED]>wrote: > Hello all, > I have written this small program But I am getting error. > > Program: > ------------- > import java.io.FileWriter; > import java.io.InputStream; > import java.sql.Connection; > import java.sql.DriverManager; > import java.sql.ResultSet; > import java.sql.Statement; > import java.text.DateFormat; > import java.text.SimpleDateFormat; > import java.util.Calendar; > import java.util.Date; > > > public class SampleHiveProgram > { > String lyear=""; > String lquarter=""; > String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; > public static void main(String[] args) > { > SampleHiveProgram s=new SampleHiveProgram(); > s.startHiveThriftServer(); > s.quarterTable(); > } > > public void startHiveThriftServer() > { > try > { > String cmd > "/home/hadoop/sqoop-1.3.0-cdh3u1/bin/StartHiveThriftServer.sh"; // this is > the command to execute in the Unix shell > // create a process for the shell > ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd); > pb.redirectErrorStream(true); // use this to capture messages > sent to stderr > Process shell = pb.start(); > InputStream shellIn = shell.getInputStream(); // this captures > the output from the command > // wait for the shell to finish and get the return code > // at this point you can process the output issued by the > command > // for instance, this reads the output and writes it to > System.out: > int c; > while ((c = shellIn.read()) != -1) > { > System.out.write(c); > } > int shellExitStatus = shell.waitFor(); > // close the stream > shellIn.close(); > } > catch(Exception e) > { > e.printStackTrace(); > System.exit(1); > } > } > > public void quarterTable() > { > try > { > String start="2010-01-01"; > String end="2011-01-01"; > System.out.println("in quarter table..."); > //create connection with database > Class.forName(driverName); > Connection con > DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", ""); > String sql=null; > Statement stmt = con.createStatement(); > ResultSet res=null; > > sql="drop table TmpQuarterTable"; > System.out.println("Dropping the Quarter Table..."); > res = stmt.executeQuery(sql); > > //Creating Quarter Table > sql="create table TmpQuarterTable (year string, quarter string, > quarterstart string, quarterend string, quartername string)" + > " ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES > TERMINATED BY '\012' STORED AS TEXTFILE "; > System.out.println("Creating the Quarter Table..."); > res = stmt.executeQuery(sql); > > //create the file > FileWriter fw=new FileWriter("/home/hadoop/Quarter.txt"); > > //convert string date to calendar date > DateFormat formatter =new SimpleDateFormat("yyyy-MM-dd"); > Date sdate=(Date)formatter.parse(start); > Date edate=(Date)formatter.parse(end); > > Calendar c1=Calendar.getInstance(); > Calendar c2=Calendar.getInstance(); > > c1.setTime(sdate); > c2.setTime(edate); > > int q=0; > String QuarterEndDate=null; > int resultMonthCount=0; > int resultYear =0; > int resultMonth =0; > > Calendar c3=Calendar.getInstance(); > c3.setTime(c1.getTime()); > while(c3.compareTo(c2)<=0) > { > if(c3.get(Calendar.MONTH)>=0 && "...:::Aniket:::... Quetzalco@tl" |