I have made a table persons in a schema name test_schema. I have connected the database from DATABASE > CONNECT TO DATABASE in mysql workbench. Then I tried to connect with that but that doesn't seem to work somehow. BTW I have cloned it from github and trying to run my database in here.
I have tried to see the status but that shows running but the data is not fetching from the database.
application.yml
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/persons
username: root
password: users
jpa:
hibernate.ddl-auto: null
generate-ddl: true
show-sql: true```
UsersRepository.java
package com.techprimers.db.repository;
import com.techprimers.db.model.Users;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UsersRepository extends JpaRepository<Users, Integer> {
}
Users.java
package com.techprimers.db.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Users {
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@Column(name = "token")
private String token;
@Column(name = "name")
private String name;
@Column(name = "post")
private Integer post;
public Users() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPost() {
return post;
}
public void setPost(Integer post) {
this.post = post;
}
}
UsersResources.java
package com.techprimers.db.resource;
import com.techprimers.db.model.Users;
import com.techprimers.db.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/rest/users")
public class UsersResource {
@Autowired
UsersRepository usersRepository;
@GetMapping(value = "/all")
public List<Users> getAll() {
return usersRepository.findAll();
}
}
SpringBootMysqldbApplication.java
package com.techprimers.db;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories(basePackages = "com.techprimers.db.repository")
@SpringBootApplication
public class SpringBootMysqldbApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootMysqldbApplication.class, args);
}
}
The result should have been the table elements but instead the Whitelabel Error Page is showing. I don't know what I have been doing wrong since there is nothing much to do. I just modified the code according to my needs but I think I somehow messed with the database connection or I am doing the database connection wrong. Thanks in advance.