//输出每个班级的得分平均值
package classes;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import DAO.HibernateSessionFactory;
import DAO.*;
public class Average {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session=HibernateSessionFactory.getSession();
String sql="from TClassname aclass";
Query query1=session.createQuery(sql);
List list1=query1.list();
Iterator it=list1.iterator();
while(it.hasNext())
{
TClassname theclass=(TClassname)it.next();
// String classid=theclass.getClassId();
Query query2=session.createQuery("select avg(credit) from TUsers users where users.TClassname=:classname");
query2.setEntity("classname", theclass);
List list2=query2.list();
System.out.println(theclass.getDes()+" : "+list2.get(0));
}
session.close();
}
}
//输出同班同学试题提交数与成功提交数
package classes;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import DAO.HibernateSessionFactory;
import DAO.TClassname;
import DAO.TUsers;
public class SubmitNumber {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session=HibernateSessionFactory.getSession();
String studentId="0706402023";
TUsers user=(TUsers)session.get(TUsers.class, studentId);
TClassname theclass=(TClassname)user.getTClassname();
Query query1=session.createQuery("from TUsers users where users.TClassname=:classname");
query1.setEntity("classname", theclass);
List list1=query1.list();
for(int index=0;index<list1.size();index++)
{
TUsers theuser=(TUsers)list1.get(index);
Query query2=session.createQuery("select count(*) from TSubmits submit where submit.TUsers=:theuser"
+" and submit.result='OK!'");
query2.setEntity("theuser", theuser);
List list2=query2.list();
Query query3=session.createQuery("select count(*) from TSubmits submit where submit.TUsers=:theuser");
query3.setEntity("theuser", theuser);
List list3=query3.list();
System.out.println(theuser.getName()+list3.get(0)+"/"+list2.get(0));
}
session.close();
}
}
package classes;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import DAO.HibernateSessionFactory;
import DAO.*;
public class Average {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session=HibernateSessionFactory.getSession();
String sql="from TClassname aclass";
Query query1=session.createQuery(sql);
List list1=query1.list();
Iterator it=list1.iterator();
while(it.hasNext())
{
TClassname theclass=(TClassname)it.next();
// String classid=theclass.getClassId();
Query query2=session.createQuery("select avg(credit) from TUsers users where users.TClassname=:classname");
query2.setEntity("classname", theclass);
List list2=query2.list();
System.out.println(theclass.getDes()+" : "+list2.get(0));
}
session.close();
}
}
//输出同班同学试题提交数与成功提交数
package classes;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import DAO.HibernateSessionFactory;
import DAO.TClassname;
import DAO.TUsers;
public class SubmitNumber {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session=HibernateSessionFactory.getSession();
String studentId="0706402023";
TUsers user=(TUsers)session.get(TUsers.class, studentId);
TClassname theclass=(TClassname)user.getTClassname();
Query query1=session.createQuery("from TUsers users where users.TClassname=:classname");
query1.setEntity("classname", theclass);
List list1=query1.list();
for(int index=0;index<list1.size();index++)
{
TUsers theuser=(TUsers)list1.get(index);
Query query2=session.createQuery("select count(*) from TSubmits submit where submit.TUsers=:theuser"
+" and submit.result='OK!'");
query2.setEntity("theuser", theuser);
List list2=query2.list();
Query query3=session.createQuery("select count(*) from TSubmits submit where submit.TUsers=:theuser");
query3.setEntity("theuser", theuser);
List list3=query3.list();
System.out.println(theuser.getName()+list3.get(0)+"/"+list2.get(0));
}
session.close();
}
}