To connect mysql database from spring boot service we need to add dependencies as below into our pom.xml.
pom.xml
1 2 3 4 5 6 7 8 9101112
<!-- we will use jpa in our project so we need to add jpa dependency --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency>
# ===============================# DB# ===============================#datasource urlspring.datasource.url=jdbc:mysql://localhost:3306/todo?useUnicode=true&characterEncoding=UTF-8#username of databasespring.datasource.username=root#password of databasespring.datasource.password=password#Database platformspring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect#configure for auto generate and update table by entitiesspring.jpa.hibernate.ddl-auto=updatespring.jpa.generate-ddl=truespring.jpa.show-sql=true
To connect oracle database from spring boot service we need to add dependencies as below into our pom.xml.
pom.yml
1 2 3 4 5 6 7 8 910111213
<!-- we will use jpa in our project so we need to add jpa dependency --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><!-- Oracle JDBC driver --><dependency><groupId>com.oracle.database.jdbc</groupId><artifactId>ojdbc8</artifactId><scope>runtime</scope></dependency>
#datasource connection configurationspring.datasource.url=jdbc:oracle:thin:@localhost:1521:XEspring.datasource.username=xespring.datasource.password=passwordspring.datasource.driver-class-name=oracle.jdbc.OracleDriver#jpa database platformspring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect#configure for auto generate and update table by entitiesspring.jpa.hibernate.ddl-auto=updatespring.jpa.generate-ddl=truespring.jpa.show-sql=true
To connect progessql database from spring boot service we need to add dependencies as below into our pom.xml.
pom.yml
1 2 3 4 5 6 7 8 9101112
<!-- we will use jpa in our project so we need to add jpa dependency --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><scope>runtime</scope></dependency>
#datasource connection configurationspring.datasource.url=jdbc:postgresql://localhost:5432/book_dbspring.datasource.username=postgresspring.datasource.password=postgresspring.datasource.driver-class-name=org.postgresql.Driver#jpa database platformspring.jpa.database=postgresqlspring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect#configure for auto generate and update table by entitiesspring.jpa.hibernate.ddl-auto=updatespring.jpa.generate-ddl=truespring.jpa.show-sql=true
To connect h2 database from spring boot service we need to add dependencies as below into our pom.xml.
pom.xml
1 2 3 4 5 6 7 8 9101112
<!-- we will use jpa in our project so we need to add jpa dependency --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope></dependency>
To save your data in h2 file, let's use jdbc:h2:file:./testdb for spring.datasource.url. In which, a file named testdb will be created in your project and all your data will be saved in this file. So if you turn off service, your data will not be lost unless you delete the this file.