Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2005

Tip: Looking for answers? Try searching our database.

metadata gettables()

Thread view: 
Jeff Kish - 23 Feb 2005 18:16 GMT
DatabaseMetaData.getTables(null, schemaName.toUpperCase(), "%", types);

I find that if I don't supply this in upper case, on Oracle 9.2, it does not
work.
So, I'm guessing this is all vendor dependant.

does Oracle always need these folded to upper case, and what about other db's.
I guess you can install ms sql server either to be case sensitive or case
insensitive - what is the best way to check for a certain table then?

I guess I'm not sure if this is a problem.. I mean the user creates the
schema's.. I don't know if it is a problem if they enter mixed/lower/upper
case for schema names.

Thanks for clarifying my mentally muddy waters.

Jeff Kish
joeNOSPAM@BEA.com - 23 Feb 2005 18:50 GMT
Hi. If a DBMS is case-insensitive with schema names you should not have
to do the toUpperCase() in this call. Oracle should have handled this,
either
in the driver or DBMS.
Joe Weinstein at BEA
frebe - 23 Feb 2005 19:10 GMT
Every database I have been working with is case-sensitive for table and
schema names. You need to supply names in the right case when you call
DatabaseMetadata.getTables().

Fredrik Bertilsson
http://butler.sourceforge.net
Thomas Kellerer - 23 Feb 2005 20:26 GMT
Jeff Kish wrote on 23.02.2005 19:21:

> I guess I'm not sure if this is a problem.. I mean the user creates the
> schema's.. I don't know if it is a problem if they enter mixed/lower/upper
> case for schema names.

When running interactive SQL Statements this is not a problem. When using
getTables() (and related) methods case does matter for Oracle.

Whether the DBMS stores this in upper or lowercase can be retrieved using
storesLowerCaseIdentifiers() or storesUpperCaseIdentifiers(). Depending on
the result of those methods I would use toUpper() or toLower()

Thomas
joeNOSPAM@BEA.com - 23 Feb 2005 21:03 GMT
Hi. If (as you'd expect) the DBMS handles this issue automatically with
fresh SQL,
the issue has to do with the DBMS processing parameter values sent via
prepared statements. There are other examples of this, such as
comparing
a CHAR(100) column value to a shorter string. The DBMS processes
the fresh SQL and silently interprets the query to expand the smaller
string
with enough blanks to make it 100 characters long, and then makes the
comparison you would want. However, if you send the smaller string via
a parameter, the comparison will fail until you manually pad it to 100
chars.
  I do not think Oracle will change any of this, so Jeff's suggestion
is
good. We hope Oracle's driver returns the correct answer to
storesUpperCaseIdentifiers()
etc ;) * 0.5.
Joe
Robert Sundström - 24 Feb 2005 11:13 GMT
>> I guess I'm not sure if this is a problem.. I mean the user creates the
>> schema's.. I don't know if it is a problem if they enter
[quoted text clipped - 8 lines]
> Depending on the result of those methods I would use toUpper() or
> toLower()

That is not the complete truth. Those methods only say how an _unquoted_
identifier will be treated. Even though the database will return true for
storesUpperCaseIdentifiers() it is perfectly possible for the database to
have lower case object names. For example, see the following SQL session:

SQL>create table "a"(c1 integer);
SQL>create table a(c1 integer);
SQL>insert into a values (1);
SQL>insert into "a" values (2);
SQL>select * from a;
         C1
===========
          1

                  1 row found

SQL>select * from "a";
         C1
===========
          2

                  1 row found

SQL>select cast(table_name as character(20)) from
information_schema.tables where
table_schema=current_user;

====================
A
a

                  2 rows found

SQL>

The above session is with Mimer SQL but I doubt Oracle behaves differently
on this issue.

From this perspective it is also clear that the meta data methods
discussed here _must_ be case sensitive to handle object created with
quoted names.

Also, any database that return false for storesUpperCaseIdentifiers() is
not in compliance with the SQL standard.
Signature

Robert Sundström, Mimer SQL Development
Mimer Information Technology AB, http://www.mimer.com
Validate your SQL statements/procedures at
http://developer.mimer.com/validator

joeNOSPAM@BEA.com - 24 Feb 2005 18:41 GMT
The OP has an issue with *schema* names, not table/column identifiers.
We'd
have to see if a DBMS has case-sensitive (or quoted! ;) ) schema names,
but
unless an oracle user scott != oracle user SCOTT, the driver should
take
care of that argument in the getTables() call.
Joe
Robert Sundström - 25 Feb 2005 20:16 GMT
> The OP has an issue with *schema* names, not table/column identifiers.
> We'd
[quoted text clipped - 3 lines]
> take
> care of that argument in the getTables() call.

Uhm.
I made a shortcut in my posting by talking about identifiers in the
general case.

I admit I am no Oracle guru, but in my humble experience, user SCOTT is
different from user scott.

create user "robert" identified by "robert";
create user "ROBERT" identified by "ROBERT";
GRANT UNLIMITED TABLESPACE TO "robert";
GRANT UNLIMITED TABLESPACE TO "ROBERT";
create table "robert".tab (c1 char(10));
create table "ROBERT".tab (c1 char(10));

In this case, the table "robert".tab would be invisible for applications
which just do .toUpperCase() in DatabaseMetaData.getTables() just for the
purpose of matching all those schemas and tables which happens to be in
all upper case.
Signature

Robert Sundström, Mimer SQL Development
Mimer Information Technology AB, http://www.mimer.com
Validate your SQL statements/procedures at
http://developer.mimer.com/validator



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.