Db2 – How to achieve federation using JDBC

db2federated-tablejdbc

I want to achieve federation using following commands through JDBC.

connect to SIGCAP_M user db2sigcp using db2sigcp ;

drop wrapper drda;
create wrapper drda ;

UNCATALOG NODE XYZ;
CATALOG TCPIP NODE XYZ REMOTE 10.XXX.XX.XX SERVER 446 ostype OS400;

UNCATALOG DB as4xyz;
CATALOG DCS DATABASE as4xyz as as4xyz;
CATALOG DB as4xyz as as4xyz AT NODE xyz authentication DCS ;

attach to xyz user "kasparov" using "kasparov123";

drop server xyz;
create server xyz type DB2/400 version 7 wrapper DRDA authorization db2ngicp PASSWORD db2ngicp options( add dbname 'S845F85V', DB2_TWO_PHASE_COMMIT  'Y'  ) ;

CREATE USER MAPPING FOR db2sigcp SERVER EQUATION OPTIONS ( ADD REMOTE_AUTHID 'db2ngicp',ADD REMOTE_PASSWORD 'db2ngicp') ;

CREATE nickname E_NEPF FOR as4xyz.KFILLV.NEPF;

As per IBM documentation – https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.sql.rtn.doc/doc/r0012547.html

SYSPROC.ADMIN_CMD doesn't support any of the above commands. How can I make this work?

Best Answer

CREATE WRAPPER, CREATE USER MAPPING and CREATE NICKNAME are all straight-forward SQL statements so you can execute them through JDBC the same as you would, say, a CREATE TABLE statement (same goes for DROP WRAPPER).

However, ATTACH, CATALOG, and UNCATALOG are entirely different beasts. They don't operate on a DB2 database, rather they affect a DB2 instance. I'm not aware of a method of executing these from JDBC (which is largely database-centric and doesn't have any special knowledge of structures "above" the database level). If all this needs to go together you're probably best off shoving it all in a batch file and executing that in a sub-process rather than trying to shoe-horn it into JDBC.

Related Question