473,766 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get "user" tables

WP
Hello, I need to communicate with a db2 database from a java program
and this java program needs to check which "user tables" there are. I
came up with the following query which I tried in Control Center:
select tabname, tabschema from syscat.tables where tabschema !=
'SYSCAT' and tabschema != 'SYSIBM' and tabschema != 'SYSIBMADM' and
tabschema != 'SYSSTAT' and tabschema != 'SYSTOOLS';
It seems to work, it returns just the tables that I have created
myself. But it is this the best way? The java program doesn't specify
a user upon connection because it's connecting through a local system
account I think. Therefore it cannot perform selection based on
username.

I just wanted to hear if I should proceed with this solution or if
there's some better approach.

- WP
Jun 27 '08 #1
5 6932
On Apr 29, 5:19 pm, WP <mindcoo...@gma il.comwrote:
Hello, I need to communicate with a db2 database from a java program
and this java program needs to check which "user tables" there are. I
came up with the following query which I tried in Control Center:
select tabname, tabschema from syscat.tables where tabschema !=
'SYSCAT' and tabschema != 'SYSIBM' and tabschema != 'SYSIBMADM' and
tabschema != 'SYSSTAT' and tabschema != 'SYSTOOLS';
It seems to work, it returns just the tables that I have created
myself. But it is this the best way? The java program doesn't specify
a user upon connection because it's connecting through a local system
account I think. Therefore it cannot perform selection based on
username.

I just wanted to hear if I should proceed with this solution or if
there's some better approach.

- WP
You could simplify the query to ... where tabschema not like 'SYS%'.
However, I'm somewhat surprised that you don't know which schema's
there are, is there some specific reason for that?

/Lennart
Jun 27 '08 #2
WP wrote:
Hello, I need to communicate with a db2 database from a java program
and this java program needs to check which "user tables" there are. I
came up with the following query which I tried in Control Center:
select tabname, tabschema from syscat.tables where tabschema !=
'SYSCAT' and tabschema != 'SYSIBM' and tabschema != 'SYSIBMADM' and
tabschema != 'SYSSTAT' and tabschema != 'SYSTOOLS';
It seems to work, it returns just the tables that I have created
myself. But it is this the best way? The java program doesn't specify
a user upon connection because it's connecting through a local system
account I think. Therefore it cannot perform selection based on
username.
Okay, you're using an "implicit" connection which means the Java app is
connecting as the user it's running under. If you wanted to find out
which tables a specific user has created you could do something like:

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = 'USERNAME'

(If you're using DB2 v8 or below, user DEFINER instead of OWNER). To
find out which tables the currently connected user has created:

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER

The following *might* work for finding all user-defined tables (I'm not
sure, there might be some exceptions):

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER <'SYSIBM'

BTW, don't use != for inequality - it's deprecated. <is standard SQL.
Cheers,

Dave.
Jun 27 '08 #3
WP
On 29 Apr, 17:37, "Dave Hughes" <d...@waveform. plus.comwrote:
WP wrote:
[snip]
>
Okay, you're using an "implicit" connection which means the Java app is
connecting as the user it's running under. If you wanted to find out
which tables a specific user has created you could do something like:

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = 'USERNAME'

(If you're using DB2 v8 or below, user DEFINER instead of OWNER). To
find out which tables the currently connected user has created:

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER
SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER; works
just fine and I think I'm going to use that. Right now, the java
program and the db2 database can be assumed to be running on the same
machine but I'm thinking maybe I should reconfigure things so the java
program has to specify username when connecting (and password maybe).
Hmm.

Thanks for the quick replies!

[snip]
>
BTW, don't use != for inequality - it's deprecated. <is standard SQL.
Ah, thanks, I will remember that. First I tried "IS NOT" but that
didn't work, heh.

By the way, I'm using verion 9.5.
>
Cheers,

Dave.
- WP
Jun 27 '08 #4
WP wrote:
On 29 Apr, 17:37, "Dave Hughes" <d...@waveform. plus.comwrote:
WP wrote:
[snip]

Okay, you're using an "implicit" connection which means the Java
app is connecting as the user it's running under. If you wanted to
find out which tables a specific user has created you could do
something like:

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER =
'USERNAME'

(If you're using DB2 v8 or below, user DEFINER instead of OWNER). To
find out which tables the currently connected user has created:

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER

SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER; works
just fine and I think I'm going to use that. Right now, the java
program and the db2 database can be assumed to be running on the same
machine but I'm thinking maybe I should reconfigure things so the java
program has to specify username when connecting (and password maybe).
Hmm.
Depends - if you can be sure the Java app will always be on the same
machine as the database I wouldn't bother adding username + password.
If there's a possibility the two will be separated at some point it'd
be worth it though.
Thanks for the quick replies!

[snip]

BTW, don't use != for inequality - it's deprecated. <is standard
SQL.

Ah, thanks, I will remember that. First I tried "IS NOT" but that
didn't work, heh.
Ah - IS and IS NOT are only used for testing for NULL ("col IS NULL",
"col IS NOT NULL"). "col = NULL" and "col <NULL" aren't useful due to
the tri-state logic that SQL employs ... "col = NULL" always evaluates
to NULL, not TRUE or FALSE (and a NULL result is equivalent to FALSE in
things like WHERE clauses).

BTW - did you pop into the #db2 channel on Freenode asking about this?
Someone asked a very similar question (involved "IS NOT"),
unfortunately it was an hour before I noticed and they'd gone by then
(it's a pretty quiet channel - usually takes a while for people to
notice anyone's said something!). Anyway, if it was you, sorry I missed
it :-)
Cheers,

Dave.
Jun 27 '08 #5
WP
On 29 Apr, 21:55, "Dave Hughes" <d...@waveform. plus.comwrote:
WP wrote:
On 29 Apr, 17:37, "Dave Hughes" <d...@waveform. plus.comwrote:
WP wrote:
[snip]
Okay, you're using an "implicit" connection which means the Java
app is connecting as the user it's running under. If you wanted to
find out which tables a specific user has created you could do
something like:
SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER =
'USERNAME'
(If you're using DB2 v8 or below, user DEFINER instead of OWNER). To
find out which tables the currently connected user has created:
SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER
SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES WHERE OWNER = USER; works
just fine and I think I'm going to use that. Right now, the java
program and the db2 database can be assumed to be running on the same
machine but I'm thinking maybe I should reconfigure things so the java
program has to specify username when connecting (and password maybe).
Hmm.

Depends - if you can be sure the Java app will always be on the same
machine as the database I wouldn't bother adding username + password.
If there's a possibility the two will be separated at some point it'd
be worth it though.
OK, I think I will leave it as it is for the meantime then.
>
Thanks for the quick replies!
[snip]
BTW, don't use != for inequality - it's deprecated. <is standard
SQL.
Ah, thanks, I will remember that. First I tried "IS NOT" but that
didn't work, heh.

Ah - IS and IS NOT are only used for testing for NULL ("col IS NULL",
"col IS NOT NULL"). "col = NULL" and "col <NULL" aren't useful due to
the tri-state logic that SQL employs ... "col = NULL" always evaluates
to NULL, not TRUE or FALSE (and a NULL result is equivalent to FALSE in
things like WHERE clauses).

BTW - did you pop into the #db2 channel on Freenode asking about this?
Someone asked a very similar question (involved "IS NOT"),
unfortunately it was an hour before I noticed and they'd gone by then
(it's a pretty quiet channel - usually takes a while for people to
notice anyone's said something!). Anyway, if it was you, sorry I missed
it :-)
Hehe, yes, that was indeed me. Then I was having slight trouble with
the actual SELECT-statement but I got it sorted (I'm rusty at SQL and
haven't worked with DB2 before). Seems to be a small but good channel
(when active). :)
>
Cheers,

Dave.
- WP
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
5126
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
4
4426
by: Ying Lu | last post by:
Hello, I have a table named "USER" under MySQL database. When I am trying to move tables from MySQL to PostgreSQL, I found that I could not create a table namely "USER". I guess "USER" is a key string used by PostgreSQL system so that we could not create a table named "USER". Is that true? Thanks a lot, Emi Lu
5
1459
by: VB Programmer | last post by:
If you want to store custom tables in ASP.NET 2.0, such as Products, Companies, Shopping Carts, etc... where is the standard place to put the tables? I want to link it to the user/membership tables. BUT, is it "ok" or the standard practice to go ahead and use the ASPNETDB.mdf to store your own tables?
3
4084
by: eighthman11 | last post by:
Hi everyone. I inherited a database that had a user name ("field") in the user group not admins. This seemed to be fine for woking with the database because it was owned by user "field" and all the tables and queries where owned by user "field". I did a compact database yesterday and now all the tables that are linked have an owner of "engine". And all the tables I created when signed in as "field" don't even show up. Like I said I...
4
3479
by: > Adrian | last post by:
System Properties show the User. I would like to be able to extract that information in an application (not change it, only retrieve it). How can that be done? Thank you, Adrian.
2
10652
by: MaxDraxyl | last post by:
Hi, I am installing DB2 Express-C on Fedora Core 6. Installation went smoothly, but I cannot create a database. $ db2 create database test SQL1092N "EMOB" does not have the authority to perform the requested command. $ grep emob /etc/passwd emob:x:500:101:Emob User:/home/emob:/bin/bash $ grep -e "^d" /etc/group
8
3059
MMcCarthy
by: MMcCarthy | last post by:
Hi everyone I had an interesting problem today with a client. I have set up security and privilege on a database depending on NT User Login. However, I've only just realised that the code returns the profile name and not the login name. This company has the profile name "USER" generic to its profiles for some strange reason. It may be a group issue, I'm not network savvy. Does anyone know of a way of retrieving the actual login name....
11
5056
by: Jan | last post by:
Hi: Here's a problem I've had for a long time. The client is really running out of patience, and I have no answers. Access2003, front- and back-end. Single form with 4 subforms (each representing a related table), 5-10 clerks doing data entry at one time. Tables are quite large but all work is done with unbound forms and/or local temp tables, and written
9
8602
by: Kelii | last post by:
Currently I have a button that allows the user to "Close Company" - at the moment it doesn't do anything :D I would like the button to "disconnect" the back end then show my Open Company form. My question is: 1. Short of closing the application or deleting the linked tables, is there a way to disconnect the user's front end from the common back end using VBA? 2. Does disconnecting the user serve any purpose? I've read a lot of posts...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.