What is causing this MySQLSyntaxError exception?

i wrote this query (in java class) to fetch some information from MySQL database and view it in jsp page ...

SELECT instructor .name FROM instructor, section, teach WHERE learn.student_id = '3'AND learn.section = section.number AND section.instructor_id = instructionor.ID

but there is an exception!

javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual corresponding to your MySQL server version for the correct syntax to use near '.student_id =' 3'AND learn.section = section.number AND section.instructor_id = ins' on line 1

By the way, I wrote it in PhpMyAdmin and it works.

Application Server: Sun GlassFish Enterprise Server v2.1

Please help me...

Hello

0


a source to share


5 answers


You will need a space after '3'

.



+6


a source


The gap seems to be missing. '.student_id =' 3'AND → '.student_id =' 3 'AND



+1


a source


If your request is listed 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 '3'

and before AND

on the first line shown above.

0


a source


What is the data type of "learn.student_id"? It is numeric or varchar. If it is a numeric value, you do not need to type "3" inside single quotes. eg learn.student_id = 3

0


a source


thanks for all

I was writing query in java class like this

ResultSet rs = stmt.executeQuery ("SELECT instructionor.name" + "From the instructor, section, teach" + "WHERE learn.student_id =" + "'" + idd + "'" + "And learn.section = section.number AND section.instructor_id = instructor.ID ");

then i delete all lines and put the query in one line like this, then it solved ...

Hello

0


a source







All Articles