Connect to another database
假定要連的是已建置好的MySQL DB
首先要透過Maven把相關的MySQL Driver抓進來
於pom內將相關的Dependency加入:
並在application.properties加入連線資訊:
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/person_example
spring.datasource.username=personuser
spring.datasource.password=YOUR_PASSWORD
其中 spring.jpa.hibernate.ddl-auto指的是 SchemaManagementTool自動執行
- none : No action will be performed.
- create-only : Database creation will be generated.
- drop : Database dropping will be generated.
- create : Database dropping will be generated followed by database creation.
- validate : Validate the database schema
- update : Update the database schema
(若只想建Table就用create就好)
相關參考:
待研究問題:
連兩個DB?
參考: