IDEA2019 3.3连接数据库

1、安装好idea后,按照以往的方式连接发现失败,于是切换各种方式尝试,最终把尝试结果记录下,希望可以帮到遇到同样问题的朋友。

错误提示①:

Driver class 'oracle.jdbc.driver.OracleDriver' not found.

解决方案:

①:使用直接加载jar包的方式:

(idea会自动下载相应数据库的驱动,但是有可能会失败)

选择自定义jars,选择自己本地的驱动文件,然后选择合适的连接方式以及jdk版本(不同的驱动依赖的jdk版本不同)

②上面的步骤做完可能依然失败(此时的错误信息挺杂乱的,就不在贴上来了),原因是新的idea可能对非英文字符支持有bug,比如2019.3.4,此时还需要设置VM参数

-Dfile.encoding=utf-8

 

 

以上即是我的个人解决方式,如果大神有更好的方式,希望一起交流下。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
1. 创建Spring Boot 2.7.0项目 可以通过Spring Initializr或者使用IDEA的Spring Initializr插件来创建Spring Boot项目。 2. 配置德鲁伊连接池 在pom.xml中添加以下依赖: ```xml <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.6</version> </dependency> ``` 在application.properties中添加以下配置: ```properties spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL spring.datasource.username=用户名 spring.datasource.password=密码 spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver # 配置德鲁伊连接池 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.initialSize=5 spring.datasource.minIdle=5 spring.datasource.maxActive=20 spring.datasource.testOnBorrow=true spring.datasource.testOnReturn=false spring.datasource.testWhileIdle=true spring.datasource.timeBetweenEvictionRunsMillis=60000 spring.datasource.minEvictableIdleTimeMillis=300000 spring.datasource.validationQuery=SELECT 1 FROM DUAL spring.datasource.filters=stat,wall,log4j spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 ``` 3. 配置mybatis-plus 在pom.xml中添加以下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.3</version> </dependency> ``` 在application.properties中添加以下配置: ```properties # mybatis-plus配置 mybatis-plus.mapper-locations=classpath*:mapper/*.xml mybatis-plus.type-aliases-package=com.example.demo.entity mybatis-plus.global-config.id-type=auto mybatis-plus.global-config.db-config.logic-delete-value=1 mybatis-plus.global-config.db-config.logic-not-delete-value=0 ``` 4. 配置Redis连接池 在pom.xml中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.7.0</version> </dependency> ``` 在application.properties中添加以下配置: ```properties # Redis连接池配置 spring.redis.host=localhost spring.redis.port=6379 spring.redis.password= spring.redis.database=0 spring.redis.timeout=3000 spring.redis.lettuce.pool.max-active=8 spring.redis.lettuce.pool.max-idle=8 spring.redis.lettuce.pool.min-idle=0 spring.redis.lettuce.pool.max-wait=-1ms ``` 5. 创建StringRedisTemplate对Redis进行操作 在Spring Boot中可以直接使用StringRedisTemplate对Redis进行操作,无需额外配置,只需要注入StringRedisTemplate即可。 ```java @Autowired private StringRedisTemplate redisTemplate; public void set(String key, String value) { redisTemplate.opsForValue().set(key, value); } public String get(String key) { return redisTemplate.opsForValue().get(key); } public void delete(String key) { redisTemplate.delete(key); } ``` 以上就是使用Spring Boot 2.7.0版本搭建项目,使用德鲁伊连接池连接Orcale数据库,使用mybatis-plus操作数据库,创建Redis连接池,使用StringRedisTemplate对Redis进行操作的步骤。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值