Later programming is based on this sample to save time on the API lookup.
private static String drivername = "Org.apache.hadoop.hive.jdbc.HiveDriver";
try{
Class.forName (drivername);//Data driven, different data drivers can be used for different class paths.
}catch (ClassNotFoundException e) {
E.printstacktrack ();//optional
System.exit (1);//optional
}
Connection con = drivermanager.getconnection ("Jdbc:hive://localhost:10000/default", "", "" ");
Drivermanager:the Basic service for managing a set of JDBC drivers.
A detailed description of the method used is as follows:
Here, Subprotocol = "Hive";
Statement stmt = Con.createstatement ();
A Statement
object represents a primitive statement in which a single method is applied to a target and a set of arguments.
A simple SQL statement that can be used to execute without parameters
String tableName = "Customerhivetablejava";
Table to be created;
ResultSet res = stmt.executequery ("CREATE TABLE" +tablename+ "(custid int, fname string,lname string) row format delimited Fields terminated by ', ' stored as textfile ');
ResultSet a table of data representing a database result set, which is usually generated by executing A statement that Q Ueries the database.
Show tables
String st = "Show tables" + TableName + "";
System.out.println ("Running:" + sql);
res = stmt.executequery (sql);//res records all returned records
if (Res.next ()) {
System.out.println (res.getstring (1));
}
Loading data into the table
String filepath = "/path";
sql = "Load data local Inpath" +filepath+ "into table" + tableName;
System.out.println ("Running:" + sql);
Sample program and parsing of Java connection hive