Question

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.

Was it helpful?

Solution

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()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top