我想做的是 从数据库随机查询一条记录。如下。用的是 mysql5.0 。
在数据库 执行sql
select * from Itas_Test_Stu i where i.testid='4028803c2718876401271888ceed0003' order by rand() limit 0,1
是没有问题的。程序代码如下:
List list = baseDAO.getObjects("from ItasTestStu i where i.testid='"+testid+"' order by rand() limit 0,1");
ItasTestStu its = (ItasTestStu)list.get(0);便报错 如下:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: limit near line 1, column 102 [from com.bzt.itas.bo.ItasTestStu i where i.testid='4028803c2718876401271888ceed0003' order by rand() limit 0,1]高手帮忙。不知道 有没有别的办法也可以实现从数据库随机抽取一条记录。。
在数据库 执行sql
select * from Itas_Test_Stu i where i.testid='4028803c2718876401271888ceed0003' order by rand() limit 0,1
是没有问题的。程序代码如下:
List list = baseDAO.getObjects("from ItasTestStu i where i.testid='"+testid+"' order by rand() limit 0,1");
ItasTestStu its = (ItasTestStu)list.get(0);便报错 如下:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: limit near line 1, column 102 [from com.bzt.itas.bo.ItasTestStu i where i.testid='4028803c2718876401271888ceed0003' order by rand() limit 0,1]高手帮忙。不知道 有没有别的办法也可以实现从数据库随机抽取一条记录。。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货