其它语言通过HiveServer2访问Hive (2)

配置文件sqlConfig.xml:

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <environments default="production"> <environment> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property value="org.apache.hive.jdbc.HiveDriver"/> <property value="jdbc:hive2://master:10000/default"/> <property value="hadoop"/> <property value="hadoop"/> </dataSource> </environment> </environments> <mappers> <mapper resource="mapper/hive/test/test.xml"/> </mappers> </configuration>

mapper代码省略,实现代码:

public classTestMapperImpl implements TestMapper { private static SqlSessionFactory sqlSessionFactory = HiveSqlSessionFactory.getInstance().getSqlSessionFactory(); @Override public int getTestCount(String dateTime) { SqlSession sqlSession = sqlSessionFactory.openSession(); TestMapper testMapper = sqlSession.getMapper(TestMapper.class); int count = testMapper.getTestCount(dateTime); sqlSession.close(); return count; } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyjppg.html