2

so tried to put that SQL code into my java-aplication:

    SELECT DISTINCT
  StRzImRo.Rohstoff, StRo.Bezeichnung,
CAST (SUM(BwLsImAt.Lieferungen * StRzImRo.Menge * StAt.PROD__REZEPTURGEWICHT / Coalesce(StRz.PARM__BEZUGSGROESSE,1))  AS NUMERIC (9,3)) Rohstoffverbrauch_Gesamt FROM BwLsImAt       

JOIN StAt ON (StAt.IntRowId = BwLsImAt.Artikel)
JOIN StRz ON (StRz.IntRowId = StAt.PROD__REZEPTUR)
JOIN StRzImRo ON (StRzImRo.Master = StRz.IntRowId)
JOIN StRo ON (StRzImRo.Rohstoff = StRo.IntRowId)
WHERE StAt.IntRowId > 0
 GROUP BY  StRzImRo.Rohstoff, StRo.Bezeichnung
-- GROUP BY  StRzImRo.Rohstoff, StRzImRo.Menge, StAt.PROD__REZEPTURGEWICHT, Coalesce(StRz.PARM__BEZUGSGROESSE,1)

The code is fully funcional and tested in IBSQL but not working in my java-application. My app does work properly with other code. I get this error:

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 266
ON

I would be very happy if someone could help me with this problem. Thanks! P.S.: Sorry for my bad language, but i´m not a native speaker

4

1 回答 1

2

该错误表明ON您的查询中有一个意外的位置,并且由于查询本身看起来很好,我猜问题在于您在 Java 应用程序中构造查询的方式。您的查询中可能缺少一些空格。

我的猜测是你有类似的东西

query = "SELECT * " +
        "FROM table1" +
        "JOIN table2 ON " //.....

缺少的空格将使 SQL:

SELECT * FROM table1JOIN table2 ON ....

对于解析器,这是完全有效的,直到它遇到ON触发错误的令牌。例如,解析器识别它是一个SELECTwith *(all) columns from table1JOINwith alias table2。在解析期间,服务器不会检查表是否确实存在,因此它不会因为table1JOIN不存在的事实而绊倒。解析成功完成后进行检查。

于 2013-07-24T13:02:55.643 回答