我在我的MySQL工作台中有一个SQL调用来测试,以便我可以确保语法是正确的,我仔细检查它是否有效,但是当我在我的java类中使用相同的语法将它传递给数据库并获取信息时得到像这样的SQLException
Error: com.mysql.jdbc.exceptions.jdbc4.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 'JOIN customers on customers.ANum = leads.ANum JOIN automobiles
on automobiles.AN' at line 1
com.mysql.jdbc.exceptions.jdbc4.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 'JOIN customers on customers.ANum = leads.ANum JOIN automobiles on
automobiles.AN' at line 1
Run Code Online (Sandbox Code Playgroud)
这是MySQL中的语法:
SELECT leads.Anum, leads.recDate, leads.status, leads.salesman, leads.apptDt,
leads.appTime, leads.notes,customers.fName, customers.mName, customers.lName,
customers.phone, customers.cell, customers.work, customers.bestTime, customers.email,
customers.addr1, customers.addr2, customers.city, customers.state, customers.zip,
customers.rentOwn, customers.pmtMo, customers.livedMo, customers.livedYr,
customers.ssn, customers.birthday, customers.employer, customers.incomeMo,
customers.empMo, customers.empYr, customers.creditApp, automobiles.newUsed,
automobiles.extColorWant, automobiles.intColorWant, automobiles.desiredInfo,
automobiles.extColor, automobiles.intColot, automobiles.yearHave, automobiles.make,
automobiles.model, automobiles.mileage, automobiles.goodPoor FROM leads JOIN customers
on customers.ANum = leads.ANum JOIN automobiles on automobiles.ANum = customers.ANum
where leads.dealer = 'SKA' and leads.recDate between '2013-01-01' and '2014-12-31'
order by leads.recDate DESC;
Run Code Online (Sandbox Code Playgroud)
My Java SQL调用的语法:
String sql = "SELECT leads.Anum, leads.recDate, leads.status, leads.salesman, leads.apptDt, leads.appTime, leads.notes,"
+ "customers.fName, customers.mName, customers.lName, customers.phone, customers.cell, customers.work,"
+ "customers.bestTime, customers.email, customers.addr1, customers.addr2, customers.city, customers.state,"
+ "customers.zip, customers.rentOwn, customers.pmtMo, customers.livedMo, customers.livedYr, customers.ssn,"
+ "customers.birthday, customers.employer, customers.incomeMo, customers.empMo, customers.empYr, customers.creditApp,"
+ "automobiles.newUsed, automobiles.extColorWant, automobiles.intColorWant, automobiles.desiredInfo, automobiles.extColor, automobiles.intColot,"
+ "automobiles.yearHave, automobiles.make, automobiles.model, automobiles.mileage, automobiles.goodPoor"
+ "FROM leads JOIN customers on customers.ANum = leads.ANum JOIN automobiles on automobiles.ANum = customers.ANum Where leads.dealer = "
+ "? and leads.recDate between ? and ? order by leads.recDate DESC";
Run Code Online (Sandbox Code Playgroud)
正如我之前所说的MySQL中的SQL调用工作正常,返回我想要它返回的内容,但我在我的java Web应用程序中得到了SQL Exception,Any Ideas可能会出错.我的第一印象是,无论出于何种原因,Java sql库都不喜欢语法,如果是这种情况,我会在哪里找到有关如何解决问题的文档.
你的生产线末端需要一个空间......
+ "automobiles.yearHave, automobiles.make, automobiles.model, automobiles.mileage, automobiles.goodPoor" <-- Space here
+ "FROM leads JOIN customers on customers.ANum = leads.ANum JOIN automobiles on automobiles.ANum = customers.ANum Where leads.dealer = "
Run Code Online (Sandbox Code Playgroud)
这导致FROM子句和SELECT子句中的字段一起运行......
...automobiles.mileage, automobiles.goodPoorFROM leads...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |