Impala通过JDBC方式访问
2024-08-31 17:39:57
不多说,直接上干货!
• 配置:
– 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("=====================================");
}
}
最后是测试结果:
更多参考
最新文章
- Java、JVM模型
- 阿里im即时通讯 h5 demo
- 彻底搞定char/wchar_t/unicode
- PyQt4多线程定时刷新控件
- 初学web开发——怎么解决无法找到路径的问题
- Innodb锁机制:Next-Key Lock 浅谈(转)
- 减小Gcc编译程序的体积
- Zookeeper 2、Zookeeper的安装和配置(集群模式)
- linux下percona-toolkit工具包的安装和使用(超详细版)
- 如何使用MFC连接Access数据库
- struts2 maven整合tiles3
- Sp_Lock
- 大公司的资深工程师和小公司的Leader如何决择?
- Algorithms code
- 零基础java的福音!史上最全最精简的学习路线图!
- 生成统计数据并导出Excel
- Excel读写方案XLSReadWriteII使用技巧总结
- 图片轮滚形式A
- winform窗体 控件【公共控件】
- http代理和SOCKS5代理的区别
热门文章
- Zero-input latency scheduler: Scheduler Overhaul
- [POI2010]KLO-Blocks(单调栈)
- 首家5G体验厅在深圳建成
- python虚拟环境virtualenv、virtualenv下运行IDLE、powershell 运行脚本由执行策略引起的问题
- [SDOI2011]消防(树的直径)
- WPF获得PNG图片外观Path数据
- 【转】CentOS下firefox安装flash说明
- ios 绘图,绘制坐标系,画坐标系
- springMVC --全局异常处理(两种方式)
- VMware中CentOS6.5启动出现An error occurred during the file system check