随笔 - 836  文章 - 1 评论 - 40 阅读 - 102万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

参考原文: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");

 

posted on   lshan  阅读(2317)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2019-09-18 kafka 高级应用 springboot2.1 (2) 手动创建topic
点击右上角即可分享
微信分享提示