I have two forms, first is for the Login and second one is the Main Form with JTable on it, that can display data from the database. This the code I used for viewing and studentlist. I can't figure out how I got the "UnsupportedOperationExemption" Error. I am new in Java. I am using Apache Netbeans.
ArrayList<Student> list;
myQuery mq = new myQuery();
public MainForm(){
initComponents();
view();
}
void view(){
list = mq.studentlist();
DefaultTableModel model = (DefaultTableModel)studTable.getModel();
Object[] row = new Object[11];
for(int i=0; i<list.size(); i++){
row[0]=list.get(i).getStudID();
row[1]=list.get(i).getLRN();
row[2]=list.get(i).getGrade();
row[3]=list.get(i).getLName();
row[4]=list.get(i).getFName();
row[5]=list.get(i).getMName();
row[6]=list.get(i).getGender();
row[7]=list.get(i).getBday();
row[8]=list.get(i).getAge();
row[9]=list.get(i).getCNumber();
row[10]=list.get(i).getAdviser();
model.addRow(row);
}
}
}
//----------------ArrayList Here---------------------------
ArrayList<Student> studentlist = new ArrayList<>();
DefaultTableModel model = new DefaultTableModel();
PreparedStatement ps;
ResultSet rs;
String query;
Student stud;
try{
query = "SELECT * FROM students";
ps = myConnection.getConnection().prepareStatement(query);
rs = ps.executeQuery();
while(rs.next()){
stud = new Student(rs.getInt("idstudents"),
rs.getInt("LRN"),
rs.getString("Grade"),
rs.getString("LName"),
rs.getString("FNname"),
rs.getString("MName"),
rs.getString("Gender"),
rs.getString("Bday"),
rs.getInt("Age"),
rs.getInt("CNumber"),
rs.getString("Adviser"));
studentlist.add(stud);
}
}catch(Exception ex){
ex.printStackTrace();
//return false;
}
return studentlist;
}
Just put a pair of backticks (``) around "students" in your query
. That declares the table in the query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.