1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
private static Connection getConn() {
/**
hiveserver org.apache.Hadoop.hive.jdbc.HiveDriver
jdbc:hive://localhost:10000/default
hiveserver2 org.apache.Hive.jdbc.HiveDriver
jdbc:hive2://localhos:10000/default
*/
String driver = "org.apache.hive.jdbc.HiveDriver";
String url = "jdbc:hive2://localhos:10000/default";
String username = "root";
String password = "";
Connection conn = null;
try {
Class.forName(driver); //classLoader,加载对应驱动
conn = (Connection) DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
|