我正在尝试将所有数据库内容显示给Jtable,但是它一直给我提供null异常 当我尝试仅将结果打印到控制台时,它可以完美运行并向我显示记录 我也试图只获取一条记录并将其显示在表中,但它确实起作用了,我真的不知道出了什么问题!*
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
int index=0;
try {
DataBase.connect();
PreparedStatement statement = DataBase.c.prepareStatement("select * from patient");
ss = statement.executeQuery();
while(ss.next())
{
p.add(new Paitent());
fillObject(ss,p.get(p.size()-1));
filltable(p.get(p.size()-1));
index++;
System.out.println("index = "+index);
}
} catch (SQLException ex) {
Logger.getLogger(PateintFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void fillObject(ResultSet s1,Paitent p) throws SQLException
{
p.setName(s1.getString("name"));
p.setId(s1.getInt("id"));
p.setGender(s1.getString("gender"));
p.setNumber_of_sessions(s1.getInt("numberofsessions"));
p.setComments(s1.getString("comments"));
p.setEntry_date((Date) s1.getObject("Date"));
p.setTherapist_name(s1.getString("therapist_name"));
p.setTherapist_id(s1.getInt("therapist_id"));
}
public void filltable(Paitent p)
{
model2.addRow(new Object[]{ p.getName(),p.getGender(),p.getNumber_of_sessions(),20,p.getComments(),p.getTherapist_name(),p.getEntry_date(),p.getTherapist_id()
} );
System.out.println("this is from filltable function patient's name is : "+p.getName());
}