
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Creating a table with MySQL - Hibernate
To create a table, you need to insert below line into application.properties −
spring.jpa.hibernate.ddl-auto=update
Here, Hibernate will create the table demo88 automatically. The application.properties code is as follows −
spring.datasource.platform=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hibernate.ddl-auto=update server.port=8191 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sampledatabase spring.datasource.username=root spring.datasource.password=123456
The demo88 entity class is as follows to create table columns −
Example
package com.automaticallytablecreation; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table public class demo88 { @Id private int id; @Column(name="name") private String name; }
The main class code is as follows −
Example
package com.automaticallytablecreation; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class AutomaticTableApplication { public static void main(String[] args) { SpringApplication.run(AutomaticTableApplication.class, args); } }
Now right click on the main class and click Run menu as Java Application. The application will run and the table gets created.
This will produce the following output −
Output
To verify, let’s display the table −
mysql> show create table demo88;
This will produce the following output −
Output
+--------+------------------------------------------------------------+
| Table | Create Table |+--------+------------------------------------------------------------+
| demo88 | CREATE TABLE `demo88` (`id` int NOT NULL,
`name` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |+--------+-------------------------------------------------------------+
1 row in set (0.03 sec)
- Related Questions & Answers
- Creating a table with a TIMESTAMP field in MySQL?
- Creating a MySQL table using Node.js
- Can we use {} while creating a MySQL table?
- Creating a MySQL Table in NodeJS using Sequelize
- Set AUTO_INCREMENT in a table while creating it in MySQL?
- Creating a hash table using Javascript
- Fix Error in MySQL syntax while creating a table column with name “index”?
- Set DEFAULT values for columns while creating a table in MySQL
- Creating a Table in MySQL to set current date as default
- Creating Unique Key in MySQL table referring to date?
- Update a MySQL table with Java MySQL
- What is the MySQL syntax error in this query – Creating a table with reserved keyword?
- While creating a MySQL table use the reserved keyword ‘Key’
- Creating a new table in SAP HANA
- Creating a table look-a-like using Tkinter