[英]Java PreparedStatement preserve table name casing
I have this Java snippet, running inside a WildFly server backed by MariaDB:我有这个 Java 片段,在 MariaDB 支持的 WildFly 服务器内运行:
var stmt = conn.prepareStatement("SELECT * FROM vehicles;");
ResultSet rs = stmt.executeQuery();
which gives me the following exception:这给了我以下例外:
org.h2.jdbc.JdbcSQLException: Table "VEHICLES" not found; SQL statement:
SELECT * FROM vehicles; [42102-193]
So, apparentally, it decided to uppercase the table name, which I don't want.因此,显然,它决定将表名大写,这是我不想要的。 How can I turn it off?我怎样才能关闭它?
That is not possible, SQL dialects are - usually - case insensitive by default, but store the table name in uppercase (some dialects will store in lowercase).这是不可能的,SQL 方言 - 通常 - 默认情况下不区分大小写,但以大写形式存储表名(某些方言将以小写形式存储)。 This means that if you use select * from vehicle
, you're actually selecting from a table called VEHICLE
, and error messages will reflect that name, because the table vehicle
is a different entity than the table VEHICLE
.这意味着如果您使用select * from vehicle
,您实际上是从名为VEHICLE
的表中进行选择,并且错误消息将反映该名称,因为表vehicle
与表VEHICLE
是不同的实体。
If you want to have the original case reflected in the error message, you need to select from a table really called vehicle
.如果您想在错误消息中反映原始情况,您需要从真正称为vehicle
的表中获取 select 。 To do that you will need to quote the object name in all your SQL statements, eg select * from "vehicle"
, or - in MariaDB and MySQL - select * from `vehicle`
. To do that you will need to quote the object name in all your SQL statements, eg select * from "vehicle"
, or - in MariaDB and MySQL - select * from `vehicle`
. Quoted object names retain their original case.引用的 object 名称保留其原始大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.