Trying to get data from Mysql db (Spring Boot + Vaadin) - java

I'm trying to get and write data to Mysql Db using Spring Boot & Vaadin. I'm new in Spring and it's too boringly to make simple web project with all of Spring's configurations. So I decided to use Spring Boot. And now my headache is - getting and writing data to Mysql Db. I wrote in application.properties configuration for DB, also "spring.jpa.hibernate.ddl-auto=create" create new table in db (if it's not exists), but no data loaded and no data added to db table. As I see from this doc https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html there is no need to write from beginning some classes to connecting db and getting data...
Please help. https://github.com/AntonKostyukewicz/VaadinCrud - here is my sources of project.

Have you looked at the Vaadin JPA Container add-on? If you are willing to talk to the DB in JPA, that's an excellent option. https://vaadin.com/docs/-/part/framework/jpacontainer/jpacontainer-overview.html

Related

h2 database and sql server in spring boot

I was asked this question by a colleague, and I am unable to answer it:
I have an in memory database (h2), and I have a SQL database server which our app needs to talk too. But due to the two different SQL dialects we are now wondering how do we get around the issue by doing the least amount of work?
This to be done in spring boot. I am aware of how to connect to the h2 database and SQL database server, but I am unsure on the rest.
If everything is setup by Spring, you should not be worried about the 2 different SQL dialects. Just be sure that spring.jpa.database is set to default to let Spring autodetect the right dialect for each datasource.
Here's a link that explain how to use/initialize two datasource in a Spring Boot projet if you need some more information.

spring boot sql database DML and DDL scripts

How i could define some schema and data to be inserted into db for
sql database in spring boot
Also could i do this for embedded databases
For example i am using two databases and i want to populate some data or define some schema and apply to different databases before application starts.
A file named import.sql in the root of the classpath is executed on startup if Hibernate creates the schema from scratch (that is, if the ddl-auto property is set to create or create-drop). This can be useful for demos and for testing if you are careful but is probably not something you want to be on the classpath in production. It is a Hibernate feature (and has nothing to do with Spring).
You can take a look in spring docs

Reading data from database that was inserted by another Spring Boot JPA project

I have two projects
ProjectA --> 'Spring Boot JPA based Java` project
ProjectB --> General 'Java' project
My Database is MySQL Server
My ProjectA is a web project so from a webpage I was able to get a lot of data inserted into multiple tables without any insert queries. This is because it's a JPA project and it was super easy.
Now I want to access the same data from the same database in a few Java classes in my ProjectB. I don't want to convert this into a Spring Boot project and make it more complex just to read data from two tables.
On the other hand I really don't want to use JDBC Connectors and process ResultSet etc. I like the way how annotations were used in Spring Boot JPA project to write and read data from the database.
What options do I have here?
You can use spring's JDBCTemplate or HibernateTemplate to minimize your code.

Database and Meta DB table for Spring batch

I am very new to Spring Batch. Tried the getting started example from spring doc. using spring-boot-starter-parent(1.5.2.RELEASE). Trying to understand where can I see the data that is inserted using this "Person" table in hsql. and also where can I see the Meta data tables for this example after execution. Please help me to understand this.
By default, Spring Boot uses an embedded database (H2, HSQL, Derby) accordingly to your dependencies.
H2 provides a great web console to view the state of your database. You'll find more informations here : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-sql-h2-console
If you'd like to stay with HSQL, please have a look at this answer : https://stackoverflow.com/a/8880390/8232755

Multiple Data Source using Spring JPA

I am building a stand alone java application using Spring JPA frame
work. I am able to access the DB in below scenario: if I give the
DB details in application.properties file as
spring.datasource.url=******** spring.datasource.username=******
spring.datasource.password=******
then it's working properly.
but I have to create two DB connections in the same application so,
I changes the names as below
spring.Datasource1.url=********* spring.Datasource1.username=******
spring.Datasource1.password
spring.Datasource2.url=************ spring.Datasource2.username=****
spring.Datasource2.password=*****
then it's not working.
Can you please provide the solution for it?
I have uploaded my code base in below location.
https://github.com/nagtej/MultipleDataSource
This might be helpful to you http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-two-datasources
Also, to connect to multiple data sources you would need to manually configure a DataSource, EntityManagerFactory and JpaTransactionManager.
For this, you can have a look at code placed at https://github.com/spring-projects/spring-data-examples/tree/master/jpa/multiple-datasources
Another good example for this is shared at http://xantorohara.blogspot.com.au/2013/11/spring-boot-jdbc-with-multiple.html

Categories