import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveTestMain {
	
	private String connectionString;
	
	private String query;
		
	private void runTestCase1() throws Exception {
		
		long startTime = System.nanoTime();
		
		for (int i=0;i<1000;i++) {
			runTestCase1Helper();
		}
		
		long endTime = System.nanoTime();
		double runningTime = (endTime - startTime) / 1000000000.0;
		System.out.println("Running time: " + runningTime);
		
	}
	
	private void runTestCase1Helper() throws Exception {
		
		Connection con = DriverManager.getConnection(connectionString, "", "");
		
		Statement stmt = con.createStatement();
		
	    ResultSet rs = stmt.executeQuery(query);
	    
	    while (rs.next()) {
	    	System.out.println("" + rs.getString(1));
	    }
	    	    
	    rs.close();
	    
	    stmt.close();
	    
	    con.close();	
	}	
	
	public HiveTestMain() throws Exception {
		
		connectionString = "jdbc:hive://adatbanyaszat.tmit.bme.hu:10000/default";
		
		query = "SHOW TABLES";
				
		runTestCase1();
		
	}
	
	private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
	
	public static void main(String[] args) throws Exception{
		
		Class.forName(driverName);
		
		new HiveTestMain();
		
	}
	
}
