配置文件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; } }