public int getCount(String registerID) throws DaoException {
if (registerID.equals(null) || registerID == null) {
if (logger.isDebugEnabled())
logger.debug("PiJobIntentionDao ID is null");
throw new DaoException("PiJobIntentionDao ID is null");
}
String sql="select count(*) from pi_workexperience where r_registerId='"+registerID+"'"; int count;
try
{
count=jt.queryForInt(sql);
if(count==0)
{
if (logger.isDebugEnabled()) {
logger.debug("get pi_workexperience is null");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new DaoException("get PI_jobIntentionCount is fail:"
+ e.getMessage());
}
return count;
}
我的count获取不到记录条数为什么
if (registerID.equals(null) || registerID == null) {
if (logger.isDebugEnabled())
logger.debug("PiJobIntentionDao ID is null");
throw new DaoException("PiJobIntentionDao ID is null");
}
String sql="select count(*) from pi_workexperience where r_registerId='"+registerID+"'"; int count;
try
{
count=jt.queryForInt(sql);
if(count==0)
{
if (logger.isDebugEnabled()) {
logger.debug("get pi_workexperience is null");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new DaoException("get PI_jobIntentionCount is fail:"
+ e.getMessage());
}
return count;
}
我的count获取不到记录条数为什么
这句代码是执行这条sql?代码了?执行报错没,这条sql在数据库能不能查到数据?
问题二:
System.out.println(registerID);//看是否有值
String sql="select count(*) from pi_workexperience where r_registerId='"+registerID+"'"
String sql="select count(*) from pi_workexperience where r_registerId='"+registerID+"'";
的下面一行打印sql,看是不是你想象中的,在sql客户端了执行看count是否为0,要是不为0,说明不是sql语句的问题,肯定就是queryForInt的问题了。
具体看看返回值,返回的int值是不是指的count的值。
4楼说的有问题吧
改成这个试试:
if (registerID.equals("") || registerID == null) {}
最好把想要的值在控制台上打一下,看看是不是自己想要的。