How to create table in lower case name - JavaDB/Derby?

那年仲夏 提交于 2019-12-22 18:06:10

问题


Is it possible to create table and it's name in lower case using JavaDB/Derby? To check if table exists I'm using:

ResultSet rs = dbmd.getTables(null, "APP", "user_properties", null);
if (!rs.next()) {/*do something*/};

But table name 'user_properties' must mach the case in catalog.


回答1:


Derby follows the ANSI standard which requires unquoted identifiers to be folded to uppercase. So, the following statement:

create table user_properties
(
   id integer not null
);

will create a table with then name USER_PROPERTIES and a column named ID.

You can force Derby to store lower case (or actually mixed cased) names by using quoted identifiers:

create table "user_properties"
(
   "id" integer not null
);

will create a table with then name user_properties and a column named id.

When you use quoted identifiers (aka "delimited identifiers") they become case-sensitive, so the second table must always be referenced using double quotes.

The statement select * from user_properties will not work if the table was created with the second statement. You have to always quote it: select * from "user_properties".

Using quoted identifiers is usually causing much more trouble than it's worth. If you never ever quote your identifiers you can safely use the upper case name in the call to getTables()



来源:https://stackoverflow.com/questions/19156565/how-to-create-table-in-lower-case-name-javadb-derby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!