2014-12-26 21 views
0
String queryString = "select DISTINCT students.firstName, teacher.firstName, Course.title" + 
    " from Student,Faculty,Course ,(select Student.ssn, Student.firstName, Enrollment.courseId" + 
    "from Enrollment, Student" + 
    "where Enrollment.ssn = Student.ssn)as students," + 
    "(select Faculty.ssn, Faculty.firstName, TaughtBy.courseId" + 
    "from TaughtBy, Faculty where TaughtBy.ssn = Faculty.ssn)as teacher" + 
    "where Student.ssn = ? and Faculty.ssn = ? and students.courseId = teacher.courseId" ; 

此sql查詢在sql server中工作,但在mysql中不起作用。 請幫幫我!什麼是在eclipse中的錯誤語法mysql

回答

0

你必須滿足的空間,具有空間嘗試之後,或者例如雙引號前:

String queryString = "select DISTINCT students.firstName, teacher.firstName, Course.title"+ " from Student,Faculty,Course ,(select Student.ssn, Student.firstName, Enrollment.courseId"+ " from Enrollment, Student"+" where Enrollment.ssn = Student.ssn)as students,"+" (select Faculty.ssn, Faculty.firstName, TaughtBy.courseId"+ " from TaughtBy, Faculty where TaughtBy.ssn = Faculty.ssn)as teacher"+ " where Student.ssn = ? and Faculty.ssn = ? and students.courseId = teacher.courseId" ; 
+0

我試了一下,並沒有奏效。 –

+0

錯誤:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL語法中有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在「where TaughtBy.ssn = Faculty.ssn」附近使用正確的語法)作爲teacher,其中Student.ssn ='111221111'和'在第1行 –

+0

還有另一個空間問題,即I糾正它。我只是在空格的情況下檢查它 – jfun