Always match hive-jdbc version with your server’s Hive version, and test first with beeline .
// 4. Execute Query Statement stmt = con.createStatement(); String sql = "SELECT * FROM employees LIMIT 5"; ResultSet res = stmt.executeQuery(sql);
public class HiveJdbcClient public static void main(String[] args) throws Exception // Hive server address (HS2) String jdbcUrl = "jdbc:hive2://192.168.1.100:10000/default;auth=noSasl"; hive server address java
Below is a standard Java snippet for connecting to a Hive server at 192.168.1.100 on port 10000 .
The standard format for a Hive connection string is: jdbc:hive2:// : / ; ; # Always match hive-jdbc version with your server’s Hive
You must include the Hive JDBC driver in your project's pom.xml . Ensure the version matches your Hive server version.
<dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version>3.1.3</version> <!-- Use your Hive version --> </dependency> The standard format for a Hive connection string
org.apache.hive hive-jdbc 3.1.2 Use code with caution. The following Java snippet demonstrates a basic connection: