我正在创建一个名为“图书馆管理系统”的项目。我面临的问题是,当我在ID的文本字段中输入数据以从数据库(MySql)检索数据以在其他“文本”上显示它时,它什么也没显示...
有人可以指导我吗
在代码中:
Bookidinput =文本字段名称
书名 =书名的文本名称(文本表示简单的Javafx FXML文本)
bookauthor =图书作者的文本名称
package lms.ui.main;
import com.jfoenix.effects.JFXDepthManager;
import java.io.IOException;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import lms.database.databaseHandler;
public class MainController implements Initializable {
@FXML
private HBox book_info;
@FXML
private HBox member_info;
@FXML
private Text bookname;
@FXML
private Text bookauthor;
@FXML
private Text member_name;
@FXML
private Text member_email;
@FXML
private TextField bookidinput;
@FXML
private TextField memberidinput;
databaseHandler handler;
@Override
public void initialize(URL url, ResourceBundle rb) {
JFXDepthManager.setDepth(book_info, 2);
JFXDepthManager.setDepth(member_info, 2);
handler = databaseHandler.getInstance();
}
@FXML
private void AddNewMember(ActionEvent event) {
loadWindow("/lms/ui/Add_Member/Add_Member.fxml", "Add New Member");
}
@FXML
private void AddNewBook(ActionEvent event) {
loadWindow("/lms/FXML_AddBook.fxml", "Add New Book");
}
@FXML
private void ListMemberTable(ActionEvent event) {
loadWindow("/lms/ui/ListMemberTable/MemberList.fxml", "Member
Table");
}
@FXML
private void ListBooKTable(ActionEvent event) {
loadWindow("/lms/ui/ListBookTable/BookList.fxml", "Book Table");
}
@FXML
private void Settings(ActionEvent event) {
}
void loadWindow(String loc, String Title){
try{
Parent root = FXMLLoader.load(getClass().getResource(loc));
Stage stage = new Stage(StageStyle.DECORATED);
stage.setTitle(Title);
stage.setScene(new Scene(root));
stage.show();
}
catch(IOException e){
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null,
e);
}
}
@FXML
private void loadbookinfo(ActionEvent event) {
String id = bookidinput.getText();
String qu = "Select * from Books where ID = ' " +
bookidinput.getText() + " ' ";
ResultSet rs = handler.exeQuery(qu) ;
Boolean flag = false;
try {
while( rs.next())
{
String bName = rs.getString("Title");
String bAuthor = rs.getString("Author");
bookname.setText(rs.getString("Title"));
bookauthor.setText(rs.getString("Author"));
flag = true;
}
} catch (SQLException ex) {
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null,
ex);
}
}
create table Books( ID varchar(30) primary key,
Title varchar(50),
Author varchar (60),
Publisher varchar(60));
insert into Books values(101, "ITM", "Stephen, Coulter, Vohra", "Bloomsbury Publishing Plc");
insert into Books values(102, "The C++ Programming Language", "Bjarne Stroustrup", "Daastan");
insert into Books values(103, "Programming: Principles and Practice Using C++", "Bjarne Stroustrup", "Pearson");
insert into Books values(104, "Modern C++ Design", "Andrei Alexandrescu", "Addison-Wesley");
insert into Books (ID,Title,Author,Publisher) values(105, "Effective C++", "Scott Meyers", "RELX Group");
我希望书名出现在“文本”中,但不会输出任何内容。强文本