views:

110

answers:

6

Hi all,

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

A: 

It would help if you post your java code (esp. the one that forms the SQL query)..

(no power to comment yet so I posted this as an answer)

mives
Thanks Mives,you are hint me to modify the query in java... : )
+5  A: 

You need a space after the '3'.

Alex Martelli
thanks Alex..i solved the problem,i use wrong way to write query in java.
+1  A: 

It seems that there is a space missing. '.student_id='3'AND -> '.student_id='3' AND

svachon
A: 

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.

Eddie
A: 

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

Shashi Bhushan
A: 

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

You should look into how to perform parameterized queries so that you don't have to deal with all this string manipulation and so that you save yourself from these types of bugs.
Frank Krueger
You are exposing yourself to sql injection attacks when doing this. Use PreparedStatement.
svachon