我们如何连接一个像 MSSQL 或者 orcale 一样的外部数据库?

2020/2/28 3:15:37

本文主要是介绍我们如何连接一个像 MSSQL 或者 orcale 一样的外部数据库?,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

让我们以 MySQL 为例来思考这个问题:

第一步 - 把 mysql 连接器的依赖项添加至 pom.xml
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId></dependency>
第二步 - 从 pom.xml 中移除 H2 的依赖项

或者至少把它作为测试的范围。

<!--
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
-->
第三步 - 安装你的 MySQL 数据库

更多的来看看这里 -https://github.com/in28minutes/jpa-with-hibernate#installing-and-setting-up-mysql

第四步 - 配置你的 MySQL 数据库连接

配置 application.properties

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/todo_examplespring.datasource.username=todouser
spring.datasource.password=YOUR_PASSWORD
第五步 - 重新启动,你就准备好了!


点击查看更多内容


这篇关于我们如何连接一个像 MSSQL 或者 orcale 一样的外部数据库?的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程