By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,557 Members | 1,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,557 IT Pros & Developers. It's quick & easy.

View Tables of DB2 Database using JDBC

P: 1
Can someone help me please with the following code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.             DatabaseMetaData metadata=con.getMetaData();
  3.             System.out.println(metadata.getDriverName());
  4.             System.out.println("Driver version: " +metadata.getDriverVersion());
  5.  
  6.             System.out.print("JDBC version: " + metadata.getJDBCMajorVersion());
  7.             System.out.println("." +metadata.getJDBCMinorVersion());
  8.  
  9.             System.out.println("Database product name: " +metadata.getDatabaseProductName());
  10.             System.out.println("Database product version: " +metadata.getDatabaseProductVersion());
  11.             System.out.print("Database version: " +metadata.getDatabaseMajorVersion());
  12.             System.out.println("." +metadata.getDatabaseMinorVersion());
  13.  
  14.             String[] names = {"TABLE"};
  15.             //exception occurs on next line:
  16.             ResultSet tables = metadata.getTables(null,"%", null, names);
  17.             while (tables.next()) {
  18.                 String tableName = tables.getString("TABLE_NAME");
  19.                 System.out.println(tableName);
  20.             }
  21.         } catch (SQLException se) {
  22.             System.out.println("Error: could not get tables");
  23.             se.printStackTrace();
  24.             System.exit(1);
  25.         }
  26.  
I get the following error, which I have not been able to resolve:

IBM DB2 JDBC Universal Driver Architecture
Driver version: 3.1.57
JDBC version: 3.0
Database product name: DB2/AIX64
Database product version: SQL09013
Database version: 9.1
Error: could not get tables
com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -443, SQLSTATE: 38553, SQLERRMC: SYSIBM.SQLTABLES;TABLES;SYSIBM:CLI:-805
at com.ibm.db2.jcc.c.fg.d(fg.java:1340)
at com.ibm.db2.jcc.b.gb.k(gb.java:351)
at com.ibm.db2.jcc.b.gb.e(gb.java:96)
at com.ibm.db2.jcc.b.w.e(w.java:83)
at com.ibm.db2.jcc.b.vb.i(vb.java:164)
at com.ibm.db2.jcc.c.fg.q(fg.java:1311)
at com.ibm.db2.jcc.c.gg.d(gg.java:2386)
at com.ibm.db2.jcc.c.hg.V(hg.java:146)
at com.ibm.db2.jcc.c.t.a(t.java:7384)
at com.ibm.db2.jcc.c.t.a(t.java:5974)
at com.ibm.db2.jcc.c.t.getTables(t.java:5885)
...
Sep 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: 1
Did you ever get a reply to this post? I ask because we are also getting the same error - DB2 version 8 fixpack 14, AIX 5.3 ML4 and ML5 - and have been unable to resolve it.

Can someone help me please with the following code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.             DatabaseMetaData metadata=con.getMetaData();
  3.             System.out.println(metadata.getDriverName());
  4.             System.out.println("Driver version: " +metadata.getDriverVersion());
  5.  
  6.             System.out.print("JDBC version: " + metadata.getJDBCMajorVersion());
  7.             System.out.println("." +metadata.getJDBCMinorVersion());
  8.  
  9.             System.out.println("Database product name: " +metadata.getDatabaseProductName());
  10.             System.out.println("Database product version: " +metadata.getDatabaseProductVersion());
  11.             System.out.print("Database version: " +metadata.getDatabaseMajorVersion());
  12.             System.out.println("." +metadata.getDatabaseMinorVersion());
  13.  
  14.             String[] names = {"TABLE"};
  15.             //exception occurs on next line:
  16.             ResultSet tables = metadata.getTables(null,"%", null, names);
  17.             while (tables.next()) {
  18.                 String tableName = tables.getString("TABLE_NAME");
  19.                 System.out.println(tableName);
  20.             }
  21.         } catch (SQLException se) {
  22.             System.out.println("Error: could not get tables");
  23.             se.printStackTrace();
  24.             System.exit(1);
  25.         }
  26.  
I get the following error, which I have not been able to resolve:

IBM DB2 JDBC Universal Driver Architecture
Driver version: 3.1.57
JDBC version: 3.0
Database product name: DB2/AIX64
Database product version: SQL09013
Database version: 9.1
Error: could not get tables
com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -443, SQLSTATE: 38553, SQLERRMC: SYSIBM.SQLTABLES;TABLES;SYSIBM:CLI:-805
at com.ibm.db2.jcc.c.fg.d(fg.java:1340)
at com.ibm.db2.jcc.b.gb.k(gb.java:351)
at com.ibm.db2.jcc.b.gb.e(gb.java:96)
at com.ibm.db2.jcc.b.w.e(w.java:83)
at com.ibm.db2.jcc.b.vb.i(vb.java:164)
at com.ibm.db2.jcc.c.fg.q(fg.java:1311)
at com.ibm.db2.jcc.c.gg.d(gg.java:2386)
at com.ibm.db2.jcc.c.hg.V(hg.java:146)
at com.ibm.db2.jcc.c.t.a(t.java:7384)
at com.ibm.db2.jcc.c.t.a(t.java:5974)
at com.ibm.db2.jcc.c.t.getTables(t.java:5885)
...
Mar 17 '08 #2

docdiesel
Expert 100+
P: 297
Hi,

I'm not a java programmer, but I may offer a workaround from DB2 side. To get a list of all non-system tables you may query the following sql statement:
Expand|Select|Wrap|Line Numbers
  1. select
  2.   creator,name
  3. from
  4.   sysibm.systables
  5. where creator not like 'SYS%' ;
This gives you the schema and the tablename. If you'd like to get the system tables as well, then just forget about the WHERE clause.

Regards,

Bernd
Mar 17 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.