Skip to content

Commit ea1bf3d

Browse files
author
Cheng Hao
committed
Add JDBCClient
1 parent d5d61e8 commit ea1bf3d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

HiveJdbcClient.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.sql.SQLException;
2+
import java.sql.Connection;
3+
import java.sql.ResultSet;
4+
import java.sql.Statement;
5+
import java.sql.DriverManager;
6+
7+
public class HiveJdbcClient {
8+
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
9+
10+
public static void main(String[] args) throws SQLException {
11+
try {
12+
Class.forName(driverName);
13+
} catch (ClassNotFoundException e) {
14+
// TODO Auto-generated catch block
15+
e.printStackTrace();
16+
System.exit(1);
17+
}
18+
Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000", "sparksql", "");
19+
Statement stmt = con.createStatement();
20+
ResultSet res = stmt.executeQuery("select key, value from src limit 5");
21+
while (res.next()) {
22+
System.out.print("result:");
23+
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)