-1

When I write the following query in SQL application, it works fine, get the result as I expected.

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

but when I try to use Java code to get same result, it has no result

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");

and I tried to remove part of the code to see how it works, and I found that as long as I add

atp_sign_book.stu_id = atp_student.stu_id

the result becomes nothing

  • 1
    [What does your step debugger tell you?](http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) because there is no way the code you posted does not throw an `Exception`. –  Nov 07 '17 at 16:36

1 Answers1

1

This should throw an error because your concatenation is wrong:

"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"

is actually do you see the problem?

"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"

If you are not getting a exception, you have way more problems than this because you are doing exception handling way wrong or this is not actually the code you are running.

The most basic step debugging or even System.out.println() would have found this.