Table of contents
1.
Introduction
2.
Vaadin
3.
MySQL
4.
Connecting to MySQL
5.
Frequently Asked Questions
5.1.
Is Vaadin an example of the Js framework?
5.2.
Is Vaadin stateless?
5.3.
Is Vaadin free?
5.4.
How can we add Javascript to Vaadin?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Connecting to MySQL

Author Urwashi Priya
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Building a full-stack web application involves a lot of moving pieces. First and foremost, we need to figure out what we will use for our frontend and backend frameworks, how we will communicate between them securely and what UI components we want to use. We also need to figure out how we will tie all of these together with some building tools and how we will maintain this whole thing for the duration of the application's lifetime.

web framework

Vaadin

Vaadin is an open-source development platform specifically designed for building web apps on Java backends. Vaadin helps in being productive by giving us everything we need to build a modern web application in one package. It gives us the components, the tools and the frameworks that we need. 

Vaadin icon

So, in this blog, we will be learning about connecting to MySQL from the Vaadin application. First, let’s discuss MySQL in brief.

MySQL

MySQL is an open-source RDBMS (relational database management system) used to modify, create and extract data from databases. Databases are essential for storing large data. It supports cross-platform, full-text indexing and uses triggers, views and cursors. MySQL Workbench is the integrated environment provided by the MySQL database.

MySQL image

So, now let’s start connecting to MySQL from the Vaadin application.

Connecting to MySQL

For CRUD operation in our web application, we use the MySQL database. So here we will learn about Connecting to MySQL

Connecting to MySQL

Step 1: The very first thing we need to do is to download and install MySQL. Then start the MySQL server.

 

Step 2: Open your project in your favourite IDE (say, Visual studio). We can run our project, say Vaadin application with Spring Boot using the command:

mvn spring-boot:run


Step 3: Make sure to start the local web server, here tomcat. Cross-check it by opening http://localhost:8080. You can see your application at this address.


Step 4: Now, let’s start connecting to MySQL:

Enter your database address and your credentials, including username and password for the database. For this, you have to open application.properties file and here type the following command. 

spring.datasource.url = jdbc:mysql://localhost:3306/
spring.datasource.username = USERNAME
spring.datasource.password = PASSWORD
You can also try this code with Online Java Compiler
Run Code

 

Step 5: make sure to add mysql-connector-java dependency and spring-boot-starter-jdbc dependency to the pom.xml file. These dependencies are added under the tag <dependency>

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<scope>runtime</scope>
</dependency>
You can also try this code with Online Java Compiler
Run Code

 

flowchart of connection

 

Frequently Asked Questions

Is Vaadin an example of the Js framework?

No, Vaadin itself is an open-source web framework in which we can develop an application without the use of HTML and CSS.

Is Vaadin stateless?

Yes, this server is stateless and allows instances to be horizontally scaled, and the services are highly available.

Is Vaadin free?

Yes, Vaadin is an open-source framework, and we can use it for free for both commercial and non-commercial purposes.

How can we add Javascript to Vaadin?

We can easily add Javascript to Vaadin using the following two methods:

(i) Using Annotations (ii) Using Page objects.

Conclusion

In this article, we have clearly discussed Vaadin and MySQL and how they can be connected to one another.  Along with a clear understanding of connecting to MySQL, we also covered some frequently asked questions. 

Recommended Readings:

After reading about Connecting to MySQL, are you not feeling excited to read/explore more articles on Database management Systems? Don't worry; Coding Ninjas has you covered. See DBMS guided path to learn. Also feel free to see and learn JavaSpring MVCGWT vs Vaadin, and  Spring Boot to learn.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Thank you

Live masterclass