ITPub博客

首页 > 架构设计 > 设计模式 > 如何连接一个像 MSSQL 或者 orcale 一样的外部数据库

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

设计模式 作者:gung123 时间:2020-02-27 15:42:14 0 删除 编辑

我们以 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
第五步 - 重新启动,你就准备好了!欢迎大家加我qq:1038774626探讨技术问题。



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69952307/viewspace-2677496/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-11-01

  • 博文量
    200
  • 访问量
    79619