简体   繁体   English

使用@(at)符号的Firebird SQL查询 - 如何在JDBC(Jaybird)中运行查询?

[英]Firebird SQL Query with @ (at) sign - How to run the query in JDBC (Jaybird)?

I have an application that uses Firebird. 我有一个使用Firebird的应用程序。 The application performs a long list of queries eg each time you list your items. 应用程序会执行一长串查询,例如每次列出项目时。 I want to take out these queries, and run them in my own Java application (so I can manipulate the list, display it, and so on.) 我想取出这些查询,并在我自己的Java应用程序中运行它们(所以我可以操作列表,显示它,等等。)

The problem is... there is a debug option in the application where you can see what kind of queries does your application run. 问题是......应用程序中有一个调试选项,您可以在其中查看应用程序运行的查询类型。 Some of the original queries got @ signs. 一些原始查询得到@符号。 If I run a query with an @ in it, I get an error. 如果我在其中运行带有@的查询,则会出错。 If I take out that part of the query, everything runs and works "as expected". 如果我取出查询的那一部分,一切都运行并按预期工作。 No errors, like a charm. 没有错误,就像一个魅力。

Detailed error message: 详细错误消息:
Error code: -104 错误代码:-104
Token unknown - line 8, column 32 令牌未知 - 第8行,第32列

We use IntelliJ IDEA which automatically applies escape characters when needed. 我们使用IntelliJ IDEA,它会在需要时自动应用转义字符。
Such a part from the original query: 来自原始查询的这样一部分:

SELECT  TBL4487."Id" "database.id",
       TBL4487."Code" "database.code",
       TBL4487."Name" "database.name",
       TBL4487."Barcode" "database.barcode",
       TBL4488."Name" "Datagroup",
       TBL4489."Name" "Mey",
       (SELECT FIRST 1   TBL4494."Price" / (CASE
    WHEN (TBL4487."GrossPrices" = @Param4495) THEN 1
    ELSE (TBL4492."Rate" + 100) / 100
END) "productprice.price"
FROM "ProductPrice" TBL4494
WHERE (TBL4494."Product" = TBL4487."Id") AND (TBL4494."PriceCategory" = @Param4497) AND (TBL4494."ValidFrom" <= @Param4498) AND (TBL4494."Currency" = @Param4499) AND (TBL4494."QuantityUnit" = TBL4487."QuantityUnit")
ORDER BY TBL4494."ValidFrom" DESC) "xyz",
       (SELECT FIRST 1   TBL4500."Price" / (CASE
    WHEN (TBL4487."GrossPrices" = @Param4501) THEN 1
    ELSE (TBL4492."Rate" + 100) / 100

The question is.. how could I run this query? 问题是..我怎么能运行这个查询? How do I replace the @ symbol? 如何更换@符号?

You can't run this query directly with Jaybird. 您不能直接使用Jaybird运行此查询。 These @ParamXXXX seem to be placeholders in the query for parameters. 这些@ParamXXXX似乎是参数查询中的占位符。 However Firebird nor Jaybird supports this type of placeholders (they only support ? as placeholder in DSQL). 然而,Firebird和Jaybird支持这种类型的占位符(它们仅支持?作为DSQL中的占位符)。

To execute this with Jaybird, you will need to replace each instance of the @ParamXXXX either with a ? 要使用Jaybird执行此操作,您需要将@ParamXXXX每个实例替换为? and set the right value for each placeholder in a PreparedStatement , or with the actual value in the query text itself. 并在PreparedStatement为每个占位符设置正确的值,或者在查询文本本身中设置实际值。

The Firebird .NET provider does support @.... -style placeholders (it translates them to Firebird-style ? placeholders), so you could try to use C#/.NET instead if you don't want to do replacing yourself. 火鸟.NET提供程序不支持@....风格的占位符(它并将它们转换为火鸟风格?占位符),所以你可以尝试使用C#/。NET,而是如果你不想做的更换自己。

Full disclosure: I am the developer of Jaybird 完全披露:我是Jaybird的开发者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Firebird的jaybird JDBC驱动程序将绑定值设置为NULL? - How to set bind values to NULL with Firebird's jaybird JDBC driver? 如何将字符串变量添加到jdbc firebird连接上的SQL查询 - How to add a string variable to a SQL query on a jdbc firebird connection Jaybird(Firebird JDBC)ResultSet FetchSize —分页持久查询 - Jaybird (Firebird JDBC) ResultSet FetchSize — Pagination long lasting queries PostGIS JDBC SQL查询 - PostGIS jdbc sql query 如何使用jdbc和sql查询编写条件? - How to write conditions using jdbc and sql query? Java JDBC类型转换(Firebird / Jaybird):在使用getter或updater ResultSet方法之前检查值/类型兼容性吗? - Java JDBC type conversion (Firebird / Jaybird): check value/type compatibility before using getter or updater ResultSet method? SQL 查询在 SQLDeveloper 中有效,但在 JDBC 中无法运行 - SQL Query works in SQLDeveloper but won't run in JDBC 如何在没有 @Query 的情况下使用 Spring Data JDBC 运行自定义 SQL? - How can I run custom SQL with Spring Data JDBC without @Query? 使用jaybird向Firebird用户授予特权 - grant privileges to Firebird user with jaybird 如何使用TomCat jdbc pool杀死运行超过1秒的SQL查询? - How kill sql query which run more than 1 seconds with help TomCat jdbc pool?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM