Connecting to MariaDB
MariaDB is a popular fork of the relational database MySQL. You need to install MariaDB separately before you can connect to it from your Vaadin application (you can also install MariaDB as a Docker container).
For an existing Vaadin project, you can connect to MariaDB by following these steps:
-
Add the
mariadb-java-clientdependency to thepom.xmlfile.Source code
pom.xml<dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version>3.0.5</version> </dependency> -
Add MariaDB configuration properties to the
src/main/resources/application.propertiesfile. You have to replaceHOST,PORT,DB_NAME,USERNAME,PASSWORDwith corresponding parameters from your MariaDB instance.Source code
application.properties# MariaDB Configuration spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mariadb://HOST:PORT/DB_NAME spring.datasource.username=USERNAME spring.datasource.password=PASSWORD spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
Caution
|
Avoid storing sensitive information in the project’s properties file.
It’s bad practice to store database URI, username, and passwords in the |
343BF5D5-D993-4273-BD94-D32DE5814898