问:从Sql DB检索数据到TextFields?

时间:2019-04-25 16:19:34

标签: java mysql sql javafx

我正在尝试从sql表中检索数据(整数和字符串)到文本字段, 我所做的就是创建一个“ TextFieldsData”类来保存数据的简洁明了,因为我在“ DataAccessObject”上设置了我处理数据库连接的类的方法,最后我在控制器类上创建了一个方法来在文本字段上显示数据。 我在运行程序时没有出现编译或运行时错误,但是我的文本字段没有任何变化! 我不知道我错过了什么。 enter image description here

class:DataAccessObject
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

    public ObservableList <TextFieldsData> getTextFieldData (String query){
    ObservableList<TextFieldsData> list = FXCollections.observableArrayList();
        try {
                connect = database.getConnection();
                pstmt = connect.prepareStatement(query);
                rs = pstmt.executeQuery();
                while(rs.next()) {
                    
                list.add(new TextFieldsData(rs.getString("ADSN_ID"),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11)));
                    }
		}catch(Exception e) {
                    e.printStackTrace();
		}
		return list;
    }; 
}
class:LayoutController
//Button
bt_db_edit.setOnAction(e->
{editFormul();
});

private void editFormul(){
    TextFieldsData items = new TextFieldsData("","","","","","","","","","","") ;
    queryy = "SELECT * FROM a4_textfields WHERE a4_textfields.ADSN_ID="+ID+"";
    doa.getTextFieldData(queryy);
    g2_txtf_1.setText(items.getG2_txtf_1());
    g2_txtf_2.setText(items.getG2_txtf_2());
    g2_txtf_3.setText(items.getG2_txtf_3());
    g2_txtf_4.setText(items.getG2_txtf_4()); 
    txtf_autre.setText(items.getTxtf_autre());
    g6_txf1.setText(items.getG6_txf1());
    txtf_hours.setText(items.getTxtf_hours());
    txtf_minutes.setText(items.getTxtf_minutes());
    g6_txf2.setText(items.getG6_txf2());
    g6_txf3.setText(items.getG2_txtf_3());
    txtf_adsn.setText(items.getADSN());  
    
    };
    
    //ID i get this from a row table it work normally 
Class:TextFieldsData
public class TextFieldsData {

private  String ADSN ;  
private  String txtf_hours ;
private  String txtf_minutes; 
private  String g2_txtf_1 ;
private  String g2_txtf_2 ;
private  String g2_txtf_3 ;
private  String g2_txtf_4 ;
private  String txtf_autre ;
private  String g6_txf1 ;
private  String g6_txf2 ;
private  String g6_txf3;


public TextFieldsData(String pADSN,String ptxtf_hours, 
                        String ptxtf_minutes ,String pg2_txtf_1 ,String pg2_txtf_2 ,String pg2_txtf_3 ,
                        String pg2_txtf_4 ,String ptxtf_autre , String pg6_txf1 ,String pg6_txf2 ,String pg6_txf3)
{
this.ADSN=new String (pADSN);
this.txtf_hours =new String (ptxtf_hours);
this.txtf_minutes =new String (ptxtf_minutes);
this.g2_txtf_1 =new String (pg2_txtf_1);
this.g2_txtf_2 =new String (pg2_txtf_2);
this.g2_txtf_3 =new String (pg2_txtf_3);
this.g2_txtf_4 =new String (pg2_txtf_4);
this.txtf_autre =new String (ptxtf_autre);
this.g6_txf1 =new String (pg6_txf1);
this.g6_txf2 =new String (pg6_txf2);
this.g6_txf3=new String (pg6_txf3);

};

    public String getADSN() {
        return ADSN;
    }
...(other get methods)

0 个答案:

没有答案