SQL语句正确,但ResultSet返回空

SQL语句正确,但在Java项目中运行,ResultSet rs的next()返回是false.
如何解决?
sqlBuf.append("select * from (");
sqlBuf.append("select apply.EXAM_TIME as check_time,apply.MONEY as money,apply.STATE as state,");
sqlBuf.append("applicate.APPLYER as applyer_name,");
sqlBuf.append("apply_remark.REMARK as remark,");
sqlBuf.append("company.NM as company_name,");
sqlBuf.append("exammer.WK as work_place ");
sqlBuf.append("FROM ");
sqlBuf.append("applicate,apply,apply_remark,company,exammer ");
sqlBuf.append("where apply.APPLICATE_ID = applicate.ID ");
sqlBuf.append("and apply.COMPANY_ID = company.ID ");
sqlBuf.append("and apply.EXAMINER_ID = exammer.ID ");
sqlBuf.append("and apply.ID = apply_remark.APPLY_ID");
sqlBuf.append(") A where A.applyer_name like '%");
sqlBuf.append(applyer);
sqlBuf.append("%' and ");
sqlBuf.append("A.company_name like '%");
sqlBuf.append(company);
sqlBuf.append("%'");

    String sql = sqlBuf.toString();

sql = "SELECT
*
FROM
(
SELECT
apply.EXAM_TIME AS check_time,
apply.MONEY AS money,
apply.STATE AS state,
applicate.APPLYER AS applyer_name,
apply_remark.REMARK AS remark,
company.NM AS company_name,
exammer.WK AS work_place
FROM
applicate,
apply,
apply_remark,
company,
exammer
WHERE
apply.APPLICATE_ID = applicate.ID
AND apply.COMPANY_ID = company.ID
AND apply.EXAMINER_ID = exammer.ID
AND apply.ID = apply_remark.APPLY_ID
) AS A,
applicate,
apply
WHERE
A.applyer_name LIKE '%范%'
AND A.company_name LIKE '%长%'"

2个回答

sqlBuf.append("where apply.APPLICATE_ID = applicate.ID ");
sqlBuf.append("and apply.COMPANY_ID = company.ID ");
sqlBuf.append("and apply.EXAMINER_ID = exammer.ID ");
sqlBuf.append("and apply.ID = apply_remark.APPLY_ID");

看下你代码的这地方应该可以修改下的
改成类似格式试试:
sqlBuf.append("where apply.APPLICATE_ID = "+applicate.ID);

a747883500
商清艾 回复Ryssun: 你查询的条件是where apply.APPLICATE_ID = applicate.ID and apply.COMPANY_ID = company.ID。。。。数据库有这样的数据么
5 年多之前 回复
u013701546
Ryssun sql语句中的ID都是数据库中的字段。SQL语句是正确的,只是返回的rs为空。
5 年多之前 回复

看着就高大上,让一个学习机械的学生去回答这样的问题,,,,估计语言不通啊

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐