Let's take a look at how various popular Databases can be configured using Spring Boot.
1. MySQL
applications.propertiesspring.datasource.url=jdbc:mysql://localhost:3306/mysqldb
spring.datasource.username=root
spring.datasource.password=msqyl-server-password
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
Maven pom.xml dependency
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
2. PostgreSQL
applications.propertiesspring.datasource.url=jdbc:postgresql://localhost:5432/postgredb
spring.datasource.username=user
spring.datasource.password=postgresql-server-password
Maven dependency pom.xml
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>43.0.1</version>
</dependency>
3. Oracle Server
applications.propertiesspring.datasource.url=jdbc:oracle:thin:@localhost:1521:oracledb
spring.datasource.username=oracle-db-user
spring.datasource.password=oracle-server-password
Maven dependency pom.xml
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>9.3.0.0</version>
</dependency>
4. Microsoft SQL Server
applications.propertiesspring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=sqldb
spring.datasource.username=sql-db-user
spring.datasource.password=sql-db-password
Maven dependency pom.xml
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.4.0.jre8</version>
</dependency>
We took a look at some Relational Databases configurations, now lets take a look at some NoSQL database configurations with Spring Boot.
1. DynamoDB
applications.propertiesspring.data.mongodb.uri=mongodb://localhost:27017/dynamodb
Maven dependency pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.6.3</version>
</dependency>
2. Cassandra
applications.propertiesspring.data.cassandra.contact-points=localhost
spring.data.cassandra.port=9042
spring.data.cassandra.keyspace-name=cassandradb
Maven dependency pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<version>2.6.3</version>
</dependency>
3. Redis
applications.propertiesspring.redis.host=localhost
spring.redis.port=6379
Maven dependency pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.6.3</version>
</dependency>
4. Apache HBase
applications.propertiesspring.data.hbase.quorum=localhost
spring.data.hbase.zk-port=2181
Maven dependency pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-hadoop</artifactId>
<version>2.6.3</version>
</dependency>
5. Couchbase
applications.propertiesspring.couchbase.bootstrap-hosts=localhost
spring.couchbase.bucket.name=bucket-name
spring.couchbase.bucket.password=server-password
Maven dependency pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
<version>2.6.3</version>
</dependency>
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to HowTos,
- [Fix] Error 1020 Cloudflare: Access was denied
- What is an Authorization Code Grant? OAuth 2.0
- Fix: psql: error: connection to server at localhost (::1) port 5432 failed: FATAL: database does not exist
- 100+ SEO Tips to improve your website search ranking
- How to submit website to dmoz directory
- How to check the version of NodeJS installed
- How to enter Rockstar Activation Code?
- Background task activation is spurious error - Windows 10, Office 2016, Office 365
- Angular CLI ng Error: You need to specify a command before moving on. Use --help to view the available commands
- cURL HTTP GET request command examples
- Fix - JioCinema Something Went Wrong Please Try Again Error 8001 while streaming IPL Cricket Live
- How to remove password from pdf file
- How to identify the version of IntelliJ
- Command: How to scp a file to remote server location?
- How to add Widgets to MacBook Desktop
- Setting up RSS feeds notifications within Outlook
- Fix - Website Connection timed out Error Code 522 (Cloudflare)
- How to fix: Please check your network connection (Retry)
- Fix: Could not connect to Redis at 127.0.0.1:6379: Connection refused
- Accept Only 0-9 Numbers RegEx Example
- How to create a New Project in Visual Studio Code (VS Code)
- Top 10 emerging breakthrough trending technologies
- Free Unlimited Calls from MTNL & BSNL Landlines from 1st May 2015
- [Error] zsh: command not found: mvn
- How to Scan iPhone for Virus? Is Antivirus it really required?
More Posts:
- Ways Compare Dates in Java Programming with Examples - Java
- [Fix] Microsoft AADSTS900561: The endpoint only accepts POST requests. Received a GET request. - Microsoft
- Check help on commands while being on sftp> prompt - FTP
- How to enable Wifi Calling on iPhone - iOS
- Java Interview Questions - Set 2: Core Principles - Java
- How to Generate SHA-512 digest in Notepad++ - NotepadPlusPlus
- How to write hello world different languages syntax - HowTos
- Permanently Set or Change $JAVA_HOME on Mac (macOS) - MacOS