Home > front end >  Three layer architecture dao used table query, query student information, name of the class
Three layer architecture dao used table query, query student information, name of the class

Time:09-17

//show the student information
Public ArrayList Showstu () {
The Connection conn=DBhelp. GetConnection ();
//note that entity class definition is empty first or you'll repeat output a query information
Student models=null;
PreparedStatement execute=null;
The ResultSet res=null;
ArrayList List=new ArrayList (a);
If (conn!=null) {
String SQL="select students. * classes. The cname from students left join classes on students. The cid=classes. The cid;";
Try {
The execute=conn. PrepareStatement (SQL);
Res.=the execute executeQuery ();
} the catch (SQLException e) {
e.printStackTrace();
}
Try {
While (res), next ()) {
Models=new Student ();
Stuid models. SetStuid (res. Get string (" "));
Models. SetStuname (res) get string (" stuname "));
Models. SetAge (res) get string (" age "));
Models. SetCid (res) get string (" cid "));
Models. SetCname (res) get string (" cname "));
List. The add (models);
}
} the catch (Exception e) {
//TODO: handle the exception
}
} else {
}
return list;
}

CodePudding user response:

What is your problem
  • Related