不多说,直接上干货!

• 配置:
  – impala.driver=org.apache.hive.jdbc.HiveDriver
  – impala.url=jdbc:hive2://node2:21050/;auth=noSasl
  – impala.username=
  – impala.password=

• 尽量使用PreparedStatement执行SQL语句:
  – 1.性能上PreparedStatement要好于Statement
  – 2.Statement存在查询不出数据的情况

下面是Java的测试代码:

  首先是引入Impala所需要的类库

  

  然后是测试代码:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Test;
public class demo {
public static Connection getConnection() throws ClassNotFoundException, SQLException{
String driver = "org.apache.hive.jdbc.HiveDriver";
String url = "jdbc:hive2://node23:21050/;auth=noSasl";
String username = "";
String password = "";
Connection conn = null;
Class.forName(driver);
conn = (Connection) DriverManager.getConnection(url,username,password);
return conn;
}
@Test
public void select() throws ClassNotFoundException, SQLException{
Connection conn = getConnection();
String sql = "select * from t_stu;";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
int col = rs.getMetaData().getColumnCount();
System.out.println("=====================================");
while (rs.next()){
for(int i=;i<=col;i++){
System.out.print(rs.getString(i)+"\t");
}
System.out.print("\n");
}
System.out.println("=====================================");
}
}

  最后是测试结果:

更多参考

http://www.cloudera.com/content/cloudera/en/documentation/cloudera-impala/latest/topics/impala_jdbc.html

最新文章

  1. Java、JVM模型
  2. 阿里im即时通讯 h5 demo
  3. 彻底搞定char/wchar_t/unicode
  4. PyQt4多线程定时刷新控件
  5. 初学web开发——怎么解决无法找到路径的问题
  6. Innodb锁机制:Next-Key Lock 浅谈(转)
  7. 减小Gcc编译程序的体积
  8. Zookeeper 2、Zookeeper的安装和配置(集群模式)
  9. linux下percona-toolkit工具包的安装和使用(超详细版)
  10. 如何使用MFC连接Access数据库
  11. struts2 maven整合tiles3
  12. Sp_Lock
  13. 大公司的资深工程师和小公司的Leader如何决择?
  14. Algorithms code
  15. 零基础java的福音!史上最全最精简的学习路线图!
  16. 生成统计数据并导出Excel
  17. Excel读写方案XLSReadWriteII使用技巧总结
  18. 图片轮滚形式A
  19. winform窗体 控件【公共控件】
  20. http代理和SOCKS5代理的区别

热门文章

  1. Zero-input latency scheduler: Scheduler Overhaul
  2. [POI2010]KLO-Blocks(单调栈)
  3. 首家5G体验厅在深圳建成
  4. python虚拟环境virtualenv、virtualenv下运行IDLE、powershell 运行脚本由执行策略引起的问题
  5. [SDOI2011]消防(树的直径)
  6. WPF获得PNG图片外观Path数据
  7. 【转】CentOS下firefox安装flash说明
  8. ios 绘图,绘制坐标系,画坐标系
  9. springMVC --全局异常处理(两种方式)
  10. VMware中CentOS6.5启动出现An error occurred during the file system check