Connecting to MySQL
MySQL is a popular relational database from Oracle. You should install MySQL separately before you can connect to it from your Vaadin application (you can also install MySQL as a Docker container).
For an existing Vaadin project, you can connect to MySQL by following the steps below:
-
Add the
mysql-connector-java
dependency to thepom.xml
file.<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>
-
Add MySQL configuration properties to the
src/main/resources/application.properties
file. You have to replaceHOST
,PORT
,DB_NAME
,USERNAME
,PASSWORD
with corresponding parameters from your MySQL instance.# MySQL Configuration spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://HOST:PORT/DB_NAME spring.datasource.username=USERNAME spring.datasource.password=PASSWORD spring.datasource.driver-class-name=com.mysql.cj.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 |
694CE8F4-DF75-41CE-8C30-5C332BA0C5E3