Accessing Hive Data Sources Using HSBroker
Description
public class JDBCExampleBroker {
private static Properties properties = new Properties();
private static void init() throws ClassNotFoundException {
properties.setProperty("user", "YourUserName");
properties.setProperty("SSL", "false");
Class.forName("io.xxxsql.jdbc.xxxDriver");
}
/**
* Program entry
*
* @param args no need program parameter
*/
public static void main(String[] args) {
Connection connection = null;
ResultSet result = null;
PreparedStatement statement = null;
String url = "jdbc:xxx://192.168.1.130:29861,192.168.1.131:29861/hive/default?serviceDiscoveryMode=hsbroker";
try {
init();
String sql = "show tables";
connection = DriverManager.getConnection(url, properties);
statement = connection.prepareStatement(sql.trim());
result = statement.executeQuery();
ResultSetMetaData resultMetaData = result.getMetaData();
Integer colNum = resultMetaData.getColumnCount();
for (int j = 1; j <= colNum; j++) {
System.out.print(resultMetaData.getColumnLabel(j) + "\t");
}
System.out.println();
while (result.next()) {
for (int j = 1; j <= colNum; j++) {
System.out.print(result.getString(j) + "\t");
}
System.out.println();
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (result != null) {
try {
result.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
} Table 1 describes the parameters in the preceding code.
| Parameter | Description |
|---|---|
| url | jdbc:xxx://HSBroker1_IP:HSBroker1_Port,HSBroker2_IP:HSBroker2_Port,HSBroker3_IP:HSBroker3_Port/catalog/schema?serviceDiscoveryMode=hsbroker NOTE:
|
| user | Username for accessing HetuEngine, that is, the username of the machine-machine user created in the cluster. |
| SSL | Indicates whether to use the HTTPS connection. The default value is false. |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot