Spring、Mybatis使用 oracle数据库的配置方式

1 Spring使用 oracle数据库的配置方式,分为两种:

1)如果是serviceName的配置方式

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver

jdbc.url=jdbc:oracle:thin:@//86.103.71.2:1521/serviceName

jdbc.username=username

jdbc.password=password

jdbc.validationQuery=SELECT 1 FROM DUAL

2)如果是SID的配置方式时,url为:

jdbc.url=jdbc:oracle:thin:@86.103.71.2:1521:SID

2 oracle常用语句

1)oracle查询表名

select table_name from all_tables where owner ='userame' and ttable_name likes '%CC%';

2)oracle根据列名称查询表名

select table_name from all_tab_columns t where t.owner ='username' and t.column_name ='colName'

3 在Mybatis中直接调用存储过程

<update id="createTableJyrz" statementType="CALLABLE">

{call HY_SSCL.create_table_jyrz()}

</update>

4 Oracle修改表字段的注释comment

comment on column 表名.列名 is '新注释';

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 添加依赖 在pom.xml文件中添加MyBatisOracle数据库的依赖: ``` <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>19.3.0.0</version> </dependency> ``` 2. 配置数据源 在application.properties或application.yml中配置数据源: ``` spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL spring.datasource.username=yourusername spring.datasource.password=yourpassword spring.datasource.driver-class-name=com.oracle.jdbc.Driver ``` 3. 配置MyBatis 在application.properties或application.yml中配置MyBatis: ``` mybatis.mapper-locations=classpath:/mapper/*.xml mybatis.type-aliases-package=com.example.demo.entity ``` 4. 创建实体类 创建对应Oracle表的实体类,注意实体类属性名要与表中字段名一致。 ``` public class User { private Long id; private String username; private String password; // getter and setter } ``` 5. 创建Mapper接口 创建UserMapper接口,并添加相应的SQL语句注解。 ``` @Mapper public interface UserMapper { @Select("SELECT * FROM user WHERE id = #{id}") User findById(Long id); // 其他查询/增加/更新/删除方法 } ``` 6. 测试 在Controller中注入UserMapper,并测试查询方法。 ``` @RestController public class UserController { @Autowired private UserMapper userMapper; @GetMapping("/user/{id}") public User getUserById(@PathVariable Long id) { return userMapper.findById(id); } } ``` 7. 运行 启动Spring Boot应用,并访问http://localhost:8080/user/{id},测试查询方法是否生效。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值