我在 Java 项目中有一个嵌入式数据库,其中有一个表 TOOLS_IMAGES,其中有两列“TOOL_id”(int)和“TOOL_image”(blob)。我尝试使用以下代码获取 blob:
rs = stmt.executeQuery("SELECT * FROM 'TOOLS_IMAGES' WHERE 'TOOL_id' = " + id);
该程序试图以这种方式一个接一个地获得15个不同的图像。当我运行程序时,它有时会设法获得一张图像,有时是两张,有时甚至是六张,但在某一时刻它总是抛出以下异常。并且在失败之后,它会为以下每个图像引发此异常:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "\'TOOLS_IMAGES\'" at line 1, column 15.
Caused by: ERROR 42X01: Syntax error: Encountered "\'TOOLS_IMAGES\'" at line 1, column 15.
为什么我在 SQL 查询中使用撇号?我已经在没有它们的情况下尝试过,但是这里 sql 将查询中的所有小写字母转换为大写字母,并在事后抱怨它找不到该列 -.- 看起来像这样:
rs = stmt.executeQuery("SELECT * FROM TOOLS_IMAGES WHERE TOOL_id = " + id);
和
java.sql.SQLSyntaxErrorException: Column 'TOOL_ID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'TOOL_ID' is not a column in the target table.
Caused by: ERROR 42X04: Column 'TOOL_ID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'TOOL_ID' is not a column in the target table.
编辑:这是我用来创建表格的脚本
create table TOOLS_IMAGES
(
"TOOL_id" INTEGER not null
constraint TOOLS_IMAGES_PK
primary key,
"TOOL_mask" BLOB,
"TOOL_img" BLOB
);
尝试使用:
ResultSet rs = stm.executeQuery("SELECT * FROM TOOLS_IMAGES WHERE \"TOOL_id\" = " + 1);
如果你放:
rs = stmt.executeQuery("SELECT * FROM TOOLS_IMAGES WHERE TOOL_id = " + id);
它将由 Derby 处理,如下所示:
rs = stmt.executeQuery("SELECT * FROM TOOLS_IMAGES WHERE TOOL_ID = " + id);
不一样的
欲了解更多信息,请访问
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句