Reputation:
How to connect Tomcat9 to a MySQL database and access the database in eclipse using Vaadin14? I already pasted the mysql connector in the tomcat\lib directory. Is there anything else to do/change?
Afterwards i created a ui that contains a few text fields and a java class car with some attributes and the corresponding getters/setters. I bound the text fields to the attributes using a binder. In my database there is also a table car with the same attributes and some entries. So how do i connect the database to my project in order to show one of the entries in my text fields and create a new entry? Sorry if this is basic java/vaadin, but i'm quite new to databases.
Upvotes: 2
Views: 154
Reputation: 2652
So how do i connect the database to my project in order to show one of the entries in my text fields and create a new entry
You first need to connect to a database. It depends on your project, how you implement it. (via Spring, for example). A good discussion on this topic is here: Connect Java to a MySQL database and some documentation here Connecting to MySQL Using the JDBC DriverManager Interface
Then you read data you need from a database. You can use ORM such as Hibernate or use a JDBC package as this. A discussion on pros/cons can be found here: What Java ORM do you prefer, and why?
Once you have your data available, you can bind an object to the binder (if you use one) or using setValue
for the fields. There is an example for Vaadin 8 here : Building a web UI for MySQL databases (in plain Java), but it should be applicable with a Vaadin 14 as well. (Or what is your version?)
You could also check a bakery starter and how connection/reading is implemented there.
Some other useful links on topic:
Upvotes: 3