Derby 嵌入式数据库奇怪的行为,SQLSyntaxErrorException

OPT_开发者

我在 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法删除嵌入式数据库的Derby系统目录

无法删除Apache Derby嵌入式数据库系统目录

NetBeans在哪里创建Derby嵌入式数据库

连接到嵌入式Derby数据库时出现java.lang.NoClassDefFoundError

derby 嵌入式数据库不采用 application.properties 的路径

Java嵌入式数据库(java db / derby)连接管理

在嵌入式驱动程序中运行的Derby数据库是否存在内存限制?

无法使用 JPA 获得与数据库的连接 - 缺少 derby 嵌入式驱动程序类

以后是否可以在客户端-服务器db环境中使用嵌入式Derby数据库?

无需完全重新安装即可重建IBM Portal嵌入式Derby数据库

带Glassfish的嵌入式Derby

重建嵌入式Derby的索引

嵌入式Derby数据库的连接字符串,可以与Swing Project的可执行文件一起导出

Java derby嵌入式数据库错误:日期/时间值的字符串表示形式的语法不正确

如何在 Dropwizard 项目(Angular 7 前端)中创建和开始使用嵌入式 Apache Derby 数据库

尝试创建 javafx 应用程序,允许用户轻松监控和维护嵌入式 derby 数据库中的网站列表

Webapp中嵌入式Derby的JDBC连接URL

Java Web应用程序中的嵌入式Derby

访问被拒绝,嵌入式Derby中存在问题

Derby 仅使用嵌入式驱动程序运行

嵌入式derby从J2C错误开始

Derby数据库如何工作?

如何使用Derby数据库?

如何在WildFly上正确关闭定义为数据源的嵌入式Derby

更新 derby 数据库中的记录不起作用

Apache Derby-检查数据库是否已创建?

无法定位的Derby数据库表

在文件系统中打开Derby / JDBC数据库

Java derby从CSV批量加载数据库