从mysql数据库导入的jtable中缺少(日期)列

时间:2018-01-28 23:17:42

标签: java mysql date jtable

所有运行corectly除了我的jtable中的日期列没有填充来自数据库mysql的数据。有什么错误吗?

public final class ClientiFrame extends javax.swing.JFrame {    

    public ClientiFrame() {
        initComponents();
        Show_Clienti_In_JTable();
    }

    //mysql java connectivity
    public Connection getConnection()
    {
       Connection con;

       try {
           con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sys", "student5", "student5");
           return con;
       } 
      catch (SQLException e) {
           return null;
       }
    }

    //creating arrayList(the problem might be here)
    public ArrayList<Client> getClientiList()
    {
       ArrayList<Client> clientiList = new ArrayList<>();
       Connection connection = getConnection();

       String query = "SELECT * FROM  clienti ";
       Statement st;
       ResultSet rs;

       try {
           st = connection.createStatement();
           rs = st.executeQuery(query);
           Client client;
           while(rs.next())
           {
               client = new Client(rs.getInt("id"),rs.getString("nume"),rs.getString("prenume"),rs.getInt("suma"),rs.getDate("data"));
               clientiList.add(client);
           }
       } catch (SQLException e) {
       }
       return clientiList;
    }

    //displaying in jtable(not good)(the problem might be here)
    public void Show_Clienti_In_JTable()
    {
       ArrayList<Client> list = getClientiList();
       DefaultTableModel model = (DefaultTableModel)jTable_Display_Clienti.getModel();
       Object[] row = new Object[5];
       for(int i = 0; i < list.size(); i++)
       {
           row[0]=list.get(i).getId();
           row[1]=list.get(i).getNume();
           row[2]=list.get(i).getPrenume();
           row[3]=list.get(i).getSuma();
           row[4]=list.get(i).getData();
           model.addRow(row);
       }
     }

这是我的客户端类

public class Client {

    private final int id;
    private final String nume;
    private final String prenume;
    private final int suma;
    private final Date data;

    public Client(int Id, String Nume, String Prenume, int Suma, Date Data)
    {
        this.id = Id;
        this.nume = Nume;
        this.prenume = Prenume;
        this.suma = Suma;
        this.data = Data;
    }

    public int getCodcli()
    {
        return id;
    }

    public String getNume()
    {
        return nume;
    }

    public String getPrenume()
    {
        return prenume;
    }

    public int getSuma()
    {
        return suma;
    }
    public Date getData()
    {
        return data;
    }
}

我的jtable有日期列 我的mysql表也有一切需要 我做了同样的方式我对其他varibles(id nume等),当我试图简单地用一个int或字符串变量替换日期它工作,但我需要日期..如果你不能弄明白可以有人发送至少我是一个教程(如何将日期数据从mysql导入jtable java。我在youtube上找不到任何东西);

0 个答案:

没有答案