添加依赖,这次使用的是druid连接池

   <!-- 阿里数据库连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>1.2.11</version>
            </dependency>
            <--access依赖-->
             <dependency>
            <groupId>net.sf.ucanaccess</groupId>
            <artifactId>ucanaccess</artifactId>
            <version>4.0.4</version>
        </dependency>
   在yml文件中配置数据源

```java
# 数据源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: net.ucanaccess.jdbc.UcanaccessDriver
        url: jdbc:ucanaccess://数据库文件路径和名字.accdb;openExclusive=false;ignoreCase=true

        druid
            # 初始连接数
            initialSize: 15
            # 最小连接池数量
            minIdle: 15
            # 最大连接池数量
            maxActive: 50
            # 配置获取连接等待超时的时间
            maxWait: 2000
            # 配置连接超时时间
            connectTimeout: 30000
            # 配置网络超时时间
            socketTimeout: 60000
            # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
            timeBetweenEvictionRunsMillis: 80000
            # 配置一个连接在池中最小生存的时间,单位是毫秒
            minEvictableIdleTimeMillis: 400000
            # 配置一个连接在池中最大生存的时间,单位是毫秒
            maxEvictableIdleTimeMillis: 900000
            # 配置检测连接是否有效
            validationQuery: SELECT 1 FROM DUAL
            testWhileIdle: true
            testOnBorrow: true
            testOnReturn: false
            webStatFilter:
                enabled: true
            statViewServlet:
                enabled: true
                # 设置白名单,不填则允许所有访问
                allow:
                url-pattern: /druid/*
            #                # 控制台管理用户名和密码
            #                login-username:
            #                login-password:
            filter:
                stat:
                    enabled: true
                    # 慢SQL记录
                    log-slow-sql: true
                    slow-sql-millis: 1000
                    merge-sql: true
                wall:
                    config:
                        multi-statement-allow: true
    jpa:
        #        hibernate:
        #            ddl-auto: update
        #        show-sql: true
        database-platform: org.hibernate.dialect.HSQLDialect

最后启动springboot服务,启动成功说明已经连接上access数据库
在这里插入图片描述


Logo

一站式 AI 云服务平台

更多推荐