i'm trying to show all database content to a Jtable , but it keeps giving me null exception when i try to just print the result to console it works perfectly and shows me the records also i tried to fetch just one record and show it in table and it worked i really dont know whats the problem !*
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());
}