If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > select all tables in a database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-04, 09:19
Pinto Pinto is offline
Registered User
 
Join Date: Dec 2003
Posts: 51
select all tables in a database

hi all ,

Can I take all the tables from a DB2 database 'sample' ? (Any sql select statement )

Can I take all the "database names" from the DB2 Database Server through java program ?

I am using the DB2 Database v8.1.3.132 ?
I am using the driver ( COM.ibm.db2.jdbc.net.DB2Driver ) to connect through java program .

-------------------------------------------------------------
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
dbconn = DriverManager.getConnection("jdbc:db2://localhost:6789/sample","administrator","password");
-------------------------------------------------------------

please help me !!!!!

thanks
Pinto
Reply With Quote
  #2 (permalink)  
Old 06-22-04, 10:07
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by Pinto
hi all ,

Can I take all the tables from a DB2 database 'sample' ? (Any sql select statement )

Can I take all the "database names" from the DB2 Database Server through java program ?

I am using the DB2 Database v8.1.3.132 ?
I am using the driver ( COM.ibm.db2.jdbc.net.DB2Driver ) to connect through java program .

-------------------------------------------------------------
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
dbconn = DriverManager.getConnection("jdbc:db2://localhost:6789/sample","administrator","password");
-------------------------------------------------------------

please help me !!!!!

thanks
Pinto
What do you mean "take"?

To get a list of tables, do a SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABLES.

I don't believe there's a way to get a database listing using Java.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 06-22-04, 10:08
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
SYSCAT.SYSTABLES has the list of tables, views, aliases, nicknames etc

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 06-22-04, 10:28
Pinto Pinto is offline
Registered User
 
Join Date: Dec 2003
Posts: 51
thanx for the reply .

Yes , to display the list of tables ...
like
"select * from tab" ( in Oracle for list the table )
"select name from sysdatabase" ( in MSSQL to display all the databases )

I applied the query

"SELECT DBNAME,NAME FROM SYSIBM.SYSTABLESPACE"

but getting an error :
--------------------
DBA2191E SQL execution error.

com.ibm.db.DataException: A
database manager error occurred. : [IBM][CLI Driver][DB2/NT]
SQL0204N "SYSIBM.SYSTABLESPACE" is an undefined name.
SQLSTATE=42704
--------------------

How can I use this SYSCAT.SYSTABLES to achieve this ?
Reply With Quote
  #5 (permalink)  
Old 06-22-04, 10:38
dsusendran dsusendran is offline
Registered User
 
Join Date: Apr 2004
Location: Inside Intel
Posts: 165
Talking

It is SYSIBM.SYSTABLES

~ Newbie
Reply With Quote
  #6 (permalink)  
Old 06-22-04, 10:44
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Sorry, I meant, SYSCAT.TABLES

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #7 (permalink)  
Old 06-23-04, 00:04
Pinto Pinto is offline
Registered User
 
Join Date: Dec 2003
Posts: 51
Thanks a lot to sathyaram_s & dsusendran ...
Yeah , It worked .
But Is there any technique to get the list of databases in a DB2 Database Server
using java program ?
Reply With Quote
  #8 (permalink)  
Old 06-23-04, 08:40
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by Pinto
Thanks a lot to sathyaram_s & dsusendran ...
Yeah , It worked .
But Is there any technique to get the list of databases in a DB2 Database Server
using java program ?
I don't think so... although the Control Center does it somehow, I'd imagine they have special hooks. I don't believe there's anything in the JDBC specs for it.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #9 (permalink)  
Old 06-23-04, 09:23
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
It can be done if the java app is launched from the CLP. (This is how th CC operates).

You can try something like this:

private javax.swing.JComboBox getDatabaseName() {
if (ivjDatabaseName == null) {
try {
ivjDatabaseName = new javax.swing.JComboBox();
ivjDatabaseName.setName("DatabaseName");
ivjDatabaseName.setBounds(249, 43, 124, 20);
// user code begin {1}
Runtime runTime;
Process child;
java.io.InputStreamReader inStream;
java.io.BufferedReader buffReader;
String inLine;
String lookValue;
String addDB;
int exitVal;

lookValue = new String(" Database alias = ");
runTime = Runtime.getRuntime();

System.out.println("List databases");
child = runTime.exec("DB2 LIST DATABASE DIRECTORY");

inStream = new java.io.InputStreamReader(child.getInputStream());
buffReader = new java.io.BufferedReader(inStream);
inLine = null;
System.out.println("Output:");
while ((inLine = buffReader.readLine()) != null) {
// System.out.println(inLine);
if (inLine.indexOf(lookValue) >= 0) {
addDB = new String(inLine.substring(lookValue.length()));
System.out.println("Found DB: " + addDB);
ivjDatabaseName.addItem(addDB);
}

}
exitVal = child.waitFor();
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjDatabaseName;
}

This works for Version 8, it differs slightly for V7.

HTH

Andy
Reply With Quote
  #10 (permalink)  
Old 06-23-04, 10:21
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by ARWinner
It can be done if the java app is launched from the CLP. (This is how th CC operates).

You can try something like this:

private javax.swing.JComboBox getDatabaseName() {
if (ivjDatabaseName == null) {
try {
ivjDatabaseName = new javax.swing.JComboBox();
ivjDatabaseName.setName("DatabaseName");
ivjDatabaseName.setBounds(249, 43, 124, 20);
// user code begin {1}
Runtime runTime;
Process child;
java.io.InputStreamReader inStream;
java.io.BufferedReader buffReader;
String inLine;
String lookValue;
String addDB;
int exitVal;

lookValue = new String(" Database alias = ");
runTime = Runtime.getRuntime();

System.out.println("List databases");
child = runTime.exec("DB2 LIST DATABASE DIRECTORY");

inStream = new java.io.InputStreamReader(child.getInputStream());
buffReader = new java.io.BufferedReader(inStream);
inLine = null;
System.out.println("Output:");
while ((inLine = buffReader.readLine()) != null) {
// System.out.println(inLine);
if (inLine.indexOf(lookValue) >= 0) {
addDB = new String(inLine.substring(lookValue.length()));
System.out.println("Found DB: " + addDB);
ivjDatabaseName.addItem(addDB);
}

}
exitVal = child.waitFor();
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjDatabaseName;
}

This works for Version 8, it differs slightly for V7.

HTH

Andy
The Java Gods are frowning at that solution.

If you're going that route, you could also use a native call to the CLI layer, SQLDataSources() should do it.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #11 (permalink)  
Old 06-24-04, 00:11
Pinto Pinto is offline
Registered User
 
Join Date: Dec 2003
Posts: 51
This works only in the machines having db2server or db2client .
I can't use this runtime.exec-streaming method , bcos my java program is running in a different machine which have no db2 client on it .

I am using the net driver (COM.ibm.db2.jdbc.net.DB2Driver) in java program to get the connection .
Any other method to do this !!!!

thanks
Reply With Quote
  #12 (permalink)  
Old 06-25-04, 00:48
Pinto Pinto is offline
Registered User
 
Join Date: Dec 2003
Posts: 51
Find the select query which list all the active database names in DB2 Database server ...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On