我想查询表mynews总共有多少条纪录,下面是我方法,总提示错误:Not supported for select queries//以下是方法,包含在pageman.java中
public int newscount() throws SQLException
{
int newscount = 0;
List list=new ArrayList();
Session session;
try 
{
session = SessionFactory.currentSession();

Query query=session.createQuery("select count(*) from Mynews"); 
newscount=query.executeUpdate();
 


catch (HibernateException e) 
{
e.printStackTrace();
SessionFactory.closeSession();


return newscount;
} //JSP页的调用
int newscount=pageman.newscount();
out.print(newscount);//试了后面加别名也不行,如 select count(*) as c from Mynews
//在线等答案,我试了如何行,当场给分

解决方案 »

  1.   

    newscount=query.executeUpdate();
    这个估计不行
    这个是更新数据库用的
      

  2.   

    问题已经解决,不过还是谢谢www203
    public Integer newscount() throws SQLException
    {
    Integer newscount = null;
    //List list=new ArrayList();
    session = SessionFactory.currentSession();   

    try 
    {


    query=session.createQuery("select count(*) from Mynews"); 
    Object ob=query.uniqueResult();
    newscount=(Integer)ob;
    //System.out.println(newscount);

    session.close();

    catch (HibernateException e) 
    {
    e.printStackTrace();




    return newscount;