java通过jdbc连接impala和pom.xml以及增查操作
来源:互联网 发布:嵌入式软件出口退税 编辑:程序博客网 时间:2024/05/17 21:44
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.insurance</groupId>
<artifactId>hiveProj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hiveProj</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-metastore</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-service</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.polyglotted/impala-jdbcimport -->
<!-- <dependency>
<groupId>org.polyglotted</groupId>
<artifactId>impala-jdbcimport</artifactId>
<version>1.0.0</version>
</dependency> -->
</dependencies>
</project>
代码:
package com.insurance.hiveProj;
import java.sql.Connection;import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ImpalaTestCase {
// here is an example query based on one of the Hue Beeswax sample tables
private static final String SQL_STATEMENT = "SELECT * FROM tab001";
// set the impalad host
private static final String IMPALAD_HOST = "10.253.128.27";
// port 21050 is the default impalad JDBC port
private static final String IMPALAD_JDBC_PORT = "21050";
private static final String CONNECTION_URL = "jdbc:hive2://" + IMPALAD_HOST + ':' + IMPALAD_JDBC_PORT + "/testdb;auth=noSasl";
private static final String JDBC_DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) {
System.out.println("\n=============================================");
System.out.println("Cloudera Impala JDBC Example");
System.out.println("Using Connection URL: " + CONNECTION_URL);
System.out.println("Running Query: " + SQL_STATEMENT);
Connection con = null;
try {
Class.forName(JDBC_DRIVER_NAME);
con = DriverManager.getConnection(CONNECTION_URL);
Statement stmt = con.createStatement();
//insert(stmt);
//delete(stmt);
ResultSet rs = stmt.executeQuery(SQL_STATEMENT);
System.out.println("\n== Begin Query Results ======================");
// print the results to the console
while (rs.next()) {
// the example query returns one String column
System.out.print(rs.getString("userid")+":");
System.out.println(rs.getString("age"));
}
System.out.println("== End Query Results =======================\n\n");
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
con.close();
} catch (Exception e) {
// swallow
}
}
}
public static void insert(Statement stmt) {
String sql = " INSERT INTO tab001(userid, age, city,name) VALUES (101, 22, 'bj','wanghongxiang001') " ;
try {
stmt.execute(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
说明: impala支持select / insert , 不支持 delete/update单行语句。
- java通过jdbc连接impala和pom.xml以及增查操作
- java通过jdbc连接impala
- java通过JDBC连接数据库及增删改查操作
- impala-jdbc-example-pom
- java 通过jdbc驱动连接hive操作
- jdbc连接impala
- 用JDBC连接Impala
- Java 通过JDBC进行数据操作(增删改查)
- java jdbc连接mysql数据库实现增删改查操作
- windows环境 java jdbc 连接impala (kerberos认证)
- java 通过jdbc驱动连接hive操作实例
- java 通过jdbc驱动连接hive操作实例
- java 通过jdbc驱动连接hive操作实例
- java 通过jdbc驱动连接hive操作实例
- JAVA通过JDBC连接并操作MySQL数据库
- java通过JDBC驱动连接操作hive实例
- java 通过jdbc驱动连接hive操作实例
- java通过jdbc连接sqlite数据库进行CRUD操作
- Ajax 后台正确执行 但在前台获取不到返回值 但打断点就可以
- OBJECT-C的编码风格跟语法格式看的好蛋疼
- c#输出农历转化及中文星期转化,string类型转化时间类型格式
- apache kafka配置中request.required.acks含义
- Android下拖动任意View代码(使用属性动画,眼前一亮)
- java通过jdbc连接impala和pom.xml以及增查操作
- ios 代码块 异步回调
- Linux的五个查找命令
- NSObject中的类方法copyWithZone问题
- VS2013类向导“异常来自 HRESULT:0x8CE0000B”错误解决方法
- Bean property 'dao' is not writable or has an invalid setter method. Does the parameter type of the
- 最近想法
- Unity3d读取自定义初始化文件
- android 设置textview获取焦点改变样式