liveBook · Manning

Database URL

As explained in Spring in Action, Sixth Edition

A database URL is a connection string that identifies a database and specifies how a client should connect to it.

A database URL is a connection string that identifies a database and tells a client how to connect. In Spring Boot, it is commonly supplied through configuration properties rather than an explicitly declared DataSource bean. section 6.1.2

A database URL works with related connection settings:

  • Spring Boot can infer the JDBC driver class from the URL structure when the driver is available. section 6.1.2
  • Username and password properties provide credentials alongside the URL. section 6.1.2
  • The configured values support automatic DataSource creation and connection-pool setup. section 6.1.2

An H2 database URL

Setting the H2 database name to tacocloud produces the JDBC URL jdbc:h2:mem:tacocloud, which can be entered in the H2 console connection settings. section 3.1.2

spring:
  datasource:
    url: jdbc:mysql:/ /localhost/tacocloud
    username: tacouser
    password: tacopassword

Use this YAML configuration to connect Spring Boot to a MySQL database with a URL, username, and password. section 6.1.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains URL configuration, driver inference, credentials, pooling, and alternatives such as JNDI without implementing a custom DataSource.
Examples
Uses jdbc:h2:mem:tacocloud for H2 and a YAML jdbc:mysql URL with credentials for MySQL.
What it assumes
Assumes basic Spring Boot configuration knowledge while demonstrating database naming, URL selection, credentials, and driver requirements.
What you can do after
Apply it via Spring Boot properties to configure database connections and access an H2 database through its console.
How it connects
Connects database URLs with configuration properties, JDBC, H2, MySQL, DataSource autoconfiguration, connection pools, and JNDI.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.