Derby Embedded 数据库异常行为,SQLSyntaxErrorException
Derby Embedded database strange behaviour, SQLSyntaxErrorException
我在 Java 项目中有一个嵌入式数据库,其中 table TOOLS_IMAGES 有两列“TOOL_id” (int) 和“TOOL_image”(斑点)。
我尝试使用以下代码获取 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.
编辑:
这是我用来创建 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);
不一样
更多信息visit
我在 Java 项目中有一个嵌入式数据库,其中 table TOOLS_IMAGES 有两列“TOOL_id” (int) 和“TOOL_image”(斑点)。 我尝试使用以下代码获取 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.
编辑: 这是我用来创建 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);
不一样
更多信息visit