SQL Firebird implementation in java/ IBSQL

五迷三道 提交于 2019-12-12 20:46:58

问题


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


回答1:


The error suggests there is an ON in an unexpected place in your query, and as the query itself looks fine, my guess is the problem is with the way you construct the query in your Java application. There might be some whitespace missing in your query.

My guess is that you have something like

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

The missing whitespace will make the SQL:

SELECT * FROM table1JOIN table2 ON ....

For the parser, this is perfectly valid until it encounters the ON token, which triggers the error. Eg the parser identifies it is a SELECT with * (all) columns from table1JOIN with alias table2. During parsing the server doesn't check if the table actually exists, so it doesn't trip over the fact that table1JOIN doesn't exist. That is checked after parsing is successfully completed.



来源:https://stackoverflow.com/questions/17831234/sql-firebird-implementation-in-java-ibsql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!