gpt4 book ai didi

java - select 子句中参数的未知数据类型错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:45 30 4
gpt4 key购买 nike

我想使用以下代码查询我的数据库(H2):

PreparedStatement x = connection.prepareStatement("INSERT INTO tree(ancestor, desc) (select ancestor,? from tree where desc = ? union all select ?,? )");
x.setInt(1,99219);
x.setInt(2,4);
x.setInt(3,99219);
x.setInt(4,99219);

但它不起作用,我收到以下错误:

org.h2.jdbc.JdbcSQLException: Unknown data type: "?, ?"; SQL statement:insert into tree(ancestor, desc) (select ancestor,? from tree where desc = ? union all select ?,? ) [50004-192]

在控制台中执行查询(没有 JDBC)工作正常。这段代码有什么问题?

最佳答案

"INSERT INTO tree(ancestor, desc) (select ancestor,? from tree where desc = ? union all select ?,? )"

此 SQL 语句不完整。此后缺少 FROM 部分:

union all select ?,?

关于java - select 子句中参数的未知数据类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40073382/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com