我想查询表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
//在线等答案,我试了如何行,当场给分
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
//在线等答案,我试了如何行,当场给分
解决方案 »
- dhx tree getUserData 返回值 undefined求解
- 诡异的报错:java.sql.SQLException: Connections could not be acquired from the underlyi
- 关于含有文件输入框得form表单提交问题
- 怎样才能登陆一个网站后显示登陆信息
- Tomcat5.5 如何限制 限制ip,限制主机访问啊???
- hibernate使用求助
- 谁能提供servlet的完整使用范例,包括各种配置,新手请教
- 标记转换
- 请问factory.dll这个组件哪里有?
- 请教一个问题?
- jsp实现文件下载时出现的问题,各位大虾帮忙啊!解决100分奉上!
- 高手快来啊,帮我看看啊~急死了!
这个估计不行
这个是更新数据库用的
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;
}