Reputation:
i written this query (in java class) to select some information from the MySQL database and view it on jsp page...
SELECT instructor.name FROM instructor,section,teach WHERE teach.student_id='3'AND teach.section = section.number AND section.instructor_id= instructor.ID
but there is exception was occur!
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.student_id='3'AND teach.section = section.number AND section.instructor_id= ins' at line 1
,,
by the way, i was write it in PhpMyAdmin, and it's work..
App server: Sun GlassFish Enterprise Server v2.1
please help me...
Regards
Upvotes: 0
Views: 173
Reputation:
Thanks for all
i was write query in java class like this
ResultSet rs =stmt.executeQuery("SELECT instructor.name " + "FROM instructor,section,teach" + "WHERE teach.student_id=" + "'" + idd + "'" + " AND teach.section = section.number AND section.instructor_id= instructor.ID");
then i eliminate all lines, and put query in one line like this, then it's solved...
Regards
Upvotes: 0
Reputation: 12743
What is the datatype of "teach.student_id"? Is it numeric or varchar. If it is numeric, no need to put the '3' inside single quotes. e.g. teach.student_id = 3
Upvotes: 0
Reputation: 54421
If your query is exactly as you show it:
SELECT instructor.name FROM instructor,section,teach WHERE teach.student_id='3'AND
teach.section = section.number AND section.instructor_id= instructor.ID
then you need a space after the '3'
and before AND
on the first line shown above.
Upvotes: 0
Reputation: 7716
It seems that there is a space missing. '.student_id='3'AND -> '.student_id='3' AND
Upvotes: 1