当我在SQL应用程序中编写以下查询时,它工作正常,得到我期望的结果。
SELECT
stu_fname,
stu_lname,
sb_classname,
sb_classdate,
sb_stime
FROM
atp_sign_book,
atp_student
WHERE
sb_classdate >= CURRENT_TIMESTAMP
AND sb_operation = 'Booking'
AND atp_sign_book.stu_id = atp_student.stu_id
ORDER BY
sb_classdate,sb_stime
但是当我尝试使用Java代码获得相同的结果时,它没有结果
ResultSet rSet = statement.executeQuery("SELECT stu_fname,stu_lname,sb_classname,sb_classdate,sb_stime"+
"FROM atp_sign_book, atp_student" +
"WHERE sb_classdate >= CURRENT_TIMESTAMP AND sb_operation = 'Booking' AND atp_sign_book.stu_id = atp_student.stu_id ORDER BY sb_classdate, sb_stime");
我试图删除部分代码以查看它是如何工作的,我发现只要我添加
atp_sign_book.stu_id = atp_student.stu_id
结果变成什么
答案 0 :(得分:1)
这会引发错误,因为你的连接是错误的:
"SELECT stu_fname,stu_lname,sb_classname,sb_classdate,sb_stime"+
"FROM atp_sign_book, atp_student" +
"WHERE sb_classdate >= CURRENT_TIMESTAMP AND sb_operation = 'Booking' AND atp_sign_book.stu_id = atp_student.stu_id ORDER BY sb_classdate, sb_stime"
实际上是你看到了问题吗?
"SELECT stu_fname,stu_lname,sb_classname,sb_classdate,sb_stimeFROM atp_sign_book, atp_studentWHERE sb_classdate >= CURRENT_TIMESTAMP AND sb_operation = 'Booking' AND atp_sign_book.stu_id = atp_student.stu_id ORDER BY sb_classdate, sb_stime"
如果你没有得到异常,你会遇到更多问题,因为你的异常处理方式是错误的,或者这实际上并不是你正在运行的代码。
最基本的调试步骤甚至是System.out.println()
都会发现这一点。