Db2

Db2

Where DBAs and data experts come together to stop operating and start innovating. Connect, share, and shape the AI era with us.


#Data


#Data
 View Only
Expand all | Collapse all

Db2 and the Java libraries...

  • 1.  Db2 and the Java libraries...

    Posted Wed March 04, 2026 11:50 AM

    Hi All,

    To my understanding, Db2, being a native C++ application (right?), will only use the Java libraries (or the JRE) in such cases as:

    -when a Java client requests a remote connection to a Db2 database (via JDBC)

    -when external Java stored procedures are being called from within a Db2 database

    Have I got this right, or completely at the wrong end of the stick?

    Also, does anyone have any ideas how I would check if my Db2 instance/database ever uses any of those Java/JAR files?

    What might work here is to set the DIAGLEVEL to 4 (at least temporarily) and then scan the db2diag.log file for any occurrences of the words such as "Java" and "JRE" (and even "JAR"), but not sure how reliable the results would be... any ideas, experiences on this one?

    Regards, Damir

     



    ------------------------------
    Damir Wilder
    Senior Consultant
    Triton Consulting
    London
    ------------------------------


  • 2.  RE: Db2 and the Java libraries...

    Posted 30 days ago
    Edited by Jan Nelken 30 days ago

    -when a Java client requests a remote connection to a Db2 database (via JDBC)

    -when external Java stored procedures are being called from within a Db2 database

    Have I got this right, or completely at the wrong end of the stick?

    Well - all sticks usually have 3 ends: Correct, Incorrect and It Depends ...

    As far as I know:
    - JDBC requests (including connection requests) are translated into DRDA verbs by client driver - by the time those DRDA statements reach Server - they look just as any DRDA request;
    - java SP is executed (or rather interpreted) by JVM - which is created and later destroyed when needed within Db2 Server by using calls like CreateJavaVM() and DestroyJavaVM();

    Gentle correction from others would be welcomed - if I am wrong ...



    ------------------------------
    Jan Nelken
    Db2 (LUW) DBA
    Open for work
    Katowice or Krakow
    +48 783 109 863
    ------------------------------



  • 3.  RE: Db2 and the Java libraries...

    Posted 30 days ago

    Hi Damir,

    Try this on the server as the instance owner:

    db2pd -fmpe

    https://www.ibm.com/docs/en/db2/12.1.x?topic=commands-db2pd-monitor-troubleshoot-db2-engine-activities#r0011729__smp-out-fmpexechistory



    ------------------------------
    Mark Barinstein
    ------------------------------



  • 4.  RE: Db2 and the Java libraries...

    Posted 26 days ago

    > being a native C++ application (right?),

    I was going to confidently(*) say "wrong", but decided to check instead: db2sysc is linked with libC.a (IBM XL C++ Runtime for AIX), so it's either a C++ application, or plays one on TV.

    (*) - I mean, it doesn't feel like a C++ application: it doesn't leak memory all over the place, it doesn't eat more memory than necessary, doesn't have a see-saw memory allocation, nor does it choke at the most inconvenient times for a garbage collection. 



    ------------------------------
    José Pina Coelho
    IT Specialist at Kyndryl
    ------------------------------



  • 5.  RE: Db2 and the Java libraries...

    Posted 24 days ago

    Fantastic comment, I love it :-)

    However, just wondering out loud... weren't Java applications supposed to have a (faulty) garbage collection - and not C++ applications, which should (mis)manage memory on their own?



    ------------------------------
    Damir Wilder
    Senior Consultant
    Triton Consulting
    London
    ------------------------------



  • 6.  RE: Db2 and the Java libraries...

    Posted 24 days ago

    From a slightly(*) hazy recollection: in C++ you could manipulate/influence the garbage collection from within the code, whereas in Java it's a task that belongs to the JVM and the closest you can go is setting good GC parameters.

    I think that in both cases, writing "good" OO code starts with recognizing that you'll never have enough memory and CPU to write "pure" OO code.

    (*) - i.e. 20 years ago.



    ------------------------------
    José Pina Coelho
    IT Specialist at Kyndryl
    ------------------------------



  • 7.  RE: Db2 and the Java libraries...

    Posted 25 days ago

    To answer your questions:
    1. When a remote JDBC connection comes to Db2, it is using DRDA protocol so no need for any Java .. it's the driver (db2jcc.jar) which is helping convert client requests and sending using DRDA to the server. 
    2.  For Java External routines, Db2 has a process called "db2fmp" which essentially loads up a JVM (which is why no Java external routine can run in unfenced mode) in its own process address space and then creates threads for connections which are calling Java routines/stored procedures.  In the load up phase it does load up the standard libraries included in Java (for I/O, network etc.) from the path  CLASSPATH directory so that it can support the calls made in the Java External SP. In Db2 v11.5 Db2 LUW uses Oracle Java whereas in Db2 v12.1 it's OpenJDK. 

    In no case, it needs to load any JAR file for any work .. Db2 just facilitates running of Java routines and just loads them up in the JVM to support the routine calls. For its native work, it's all C libraries (.so or .a). 

    Hope this helps.

    Rajib

    AWS RDS Db2



    ------------------------------
    Rajib Sarkar
    ------------------------------



  • 8.  RE: Db2 and the Java libraries...

    Posted 24 days ago

    Hi Rajib,

    Thanks for your answers, they do make a lot of sense.

    And they also confirm what Jan mentioned above (JDBC calls being translated into DRDA protocol).

    Regarding the FMPs, we should be able to figure out if they ever (since the last instance restart?) used Java (JVM) by running the command that Mark mentioned (also above):

    db2pd -fmpe

    Is that right (the command is supposed to give some history on the db2fmp usage, but the documentation is pretty vague on what exactly that is)?

    Regards, Damir



    ------------------------------
    Damir Wilder
    Senior Consultant
    Triton Consulting
    London
    ------------------------------



  • 9.  RE: Db2 and the Java libraries...

    Posted 24 days ago

    You can find out the FMP serving Java routines (i.e. it has loaded the JVM into its address space) using db2pd -fmp ( the flags should have 0x3 at the end .. 0x1 its a java fmp and 0x2 for it being threaded (i.e. each thread serving a separate call to Java SPs.) .. db2pd -fmpexechistory (short form is -fmpe) is to find out what each process ran which can also help figure out which process is serving the Java routines. 

    Thanks

    Rajib



    ------------------------------
    Rajib Sarkar
    ------------------------------



  • 10.  RE: Db2 and the Java libraries...

    Posted 23 days ago
    -To check if any of the Java/JAR files are used, query the SYSCAT.ROUTINES catalog view.DB2 executes Java code stored in the JARs
    SELECT ROUTINENAME, LANGUAGE
    FROM SYSCAT.ROUTINES
    WHERE LANGUAGE = 'JAVA';

    -If client applications connect via JDBC, they use the db2jcc.jar or db2jcc4.jar driver. These drivers are typically found in the /sqllib/java or /sqllib/jdbc directories.
     Db2 logs connection details in db2diag.log and look for entries mentioning JDBC driver names.