Answer the question
In order to leave comments, you need to log in
How to make sql query from MySQL to TableView?
I need to display data from MySQL in TableView. Deployed Spring, made a connection to the database:
spring.datasource.url=jdbc:mysql://localhost:3306/usersdb?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
server.port=8080
public class ModelTable
{
String id, login, password, surname, name;
public ModelTable(String id, String login, String password, String surname, String name)
{
this.id = id;
this.login = login;
this.password = password;
this.surname = surname;
this.name = name;
}
//здесь сеттеры и геттеры
}
public class TableController implements Initializable
{
@FXML
private TableView<ModelTable> table;
@FXML
private TableColumn<ModelTable, String> userId;
@FXML
private TableColumn<ModelTable, String> userLogin;
@FXML
private TableColumn<ModelTable, String> userPass;
@FXML
private TableColumn<ModelTable, String> userSurname;
@FXML
private TableColumn<ModelTable, String> userName;
ObservableList<ModelTable> list = FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources)
{
//id, login, password, surname, name
userId.setCellValueFactory(new PropertyValueFactory<>("id"));
userLogin.setCellValueFactory(new PropertyValueFactory<>("login"));
userPass.setCellValueFactory(new PropertyValueFactory<>("password"));
userSurname.setCellValueFactory(new PropertyValueFactory<>("surname"));
userName.setCellValueFactory(new PropertyValueFactory<>("name"));
//если правильно понял запрос должен быть здесь
}
}
Answer the question
In order to leave comments, you need to log in
Good evening.
I would ask you to specify your question a little, because the following points are not clear:
1) Is your project a client-server application? If so, do I understand correctly that you have a client - JavaFX and a server - Spring Boot. If so, then it turns out that you want to execute a request from the client to the server and get the data stored in the database. In this case, you need to write a REST service on the server side (in Spring). For example, a controller that processes GET requests and returns the corresponding data in json format. Then on a successful response, your client (javaFX) parses the json and maps it to the pojo. After that it is displayed in the TableView.
Based on the above, the answer to your question is:
Can you tell me how to query the database?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question