Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Other Languages
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Other Languages
springboot jpa web project
obaid abbassi
Ranch Hand
Posts: 118
posted 1 year ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am using springboot data jpa to save my employee here is my entity class
import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @Entity public class Employee { public int getEmpId() { return EmpId; } public void setEmpId(int empId) { EmpId = empId; } @Override public String toString() { return "Employee{" + "EmpId=" + EmpId + ", EmpName=" + EmpName + '}'; } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int EmpId; public String getEmpName() { return EmpName; } public void setEmpName(String empName) { EmpName = empName; } private String EmpName; }
this is my service class
import com.example.rest_springboot_jpa.Entity.Employee; import com.example.rest_springboot_jpa.Repository.EmployeeRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class EmployeeService { @Autowired EmployeeRepository employeeRepository; public void addEmployee(Employee employee){ employeeRepository.save(employee); } }
this is my employee repository
package com.example.rest_springboot_jpa.Repository; import com.example.rest_springboot_jpa.Entity.Employee; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.RestController; public interface EmployeeRepository extends CrudRepository<Employee,Integer> { }
this is my controller class
package com.example.rest_springboot_jpa.Controller; import com.example.rest_springboot_jpa.Entity.Employee; import com.example.rest_springboot_jpa.Repository.EmployeeRepository; import com.example.rest_springboot_jpa.Service.EmployeeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController public class EmployeeController { @Autowired EmployeeRepository employeeRepository; @Autowired EmployeeService employeeService; @PostMapping("/add" ) public void addEmployee(Employee employee,@RequestParam("name") String name){ employee.setEmpName(name); employeeService.addEmployee(employee); } }
this is my simple
jsp
page
<form method="post" action="/add"> <input type="text" placeholder="enter your text" name="name"> <input type="submit"> </form> Now when i submit value to controller I got error says java.sql.SQLSyntaxErrorException: Table 'emp.employee' doesn't exist at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.30.jar:8.0.30] asking me for table so Its not my resposiblilty to create table why jpa not creating table this is properties file spring.datasource.url=jdbc:mysql://localhost:3306/emp spring.datasource.username=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.password= spring.jpa.properties.hibernate.Dialect=org.hibernate.dialect.MySQL55Dialect spring.jpa.hibernate.ddt-auto=create
permaculture is largely about replacing oil with people. And one tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
404 Error When Using Spring + Hibernate in My Project.
Problem with SpringBoot in Eclipse
Sending email through springboot and angular
Architectural Interface to support dynamic Data source(s) (Java)
How to update using Hibernate
More...