参考原文:https://blog.csdn.net/Sunhighlight/article/details/89044374
依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.16.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-jdbc</artifactId>
<version>0.203</version>
</dependency>
配置application.yml文件
datasource: presto: name: presto type: org.apache.tomcat.jdbc.pool.DataSource driver-class-name: com.facebook.presto.jdbc.PrestoDriver url: jdbc:presto://192.168.18.129:8881/test/sea username: root
注意:
(1)本项目其他数据源使用的是阿里巴巴druid数据库连接池,但是该连接池不支持PrestoDB,如果使用会爆出:java.lang.IllegalStateException: dbType not support错误,故我们用org.apache.tomcat.jdbc.pool.DataSource连接池
3.3创建数据源配置类
@Configuration public class GlobalDataSourceConfiguration { private static Logger LOG = LoggerFactory.getLogger(GlobalDataSourceConfiguration.class); @Bean(name = "prestoDataSource") @ConfigurationProperties(prefix = "datasource.presto") public DataSource prestoDataSource() { LOG.info("-------------------- presto init ---------------------"); return DataSourceBuilder.create().build(); } @Bean(name = "prestoTemplate") public JdbcTemplate prestoJdbcTemplate(@Qualifier("prestoDataSource") DataSource dataSource) { return new JdbcTemplate(dataSource); } }
4.3使用prestoDB直接执行SQL
@Autowired @Qualifier("prestoTemplate") private JdbcTemplate prestoTemplate; List<Map<String, Object>> result = prestoTemplate.queryForList("sql");