Skip to content

Instantly share code, notes, and snippets.

@worksofliam
Created October 20, 2020 00:18
Show Gist options
  • Save worksofliam/fc6191caa66b89635f4a0624c8ca5b40 to your computer and use it in GitHub Desktop.
Save worksofliam/fc6191caa66b89635f4a0624c8ca5b40 to your computer and use it in GitHub Desktop.

Order process for JDBC connection creation

This is specifically for jtopenlite.

  1. JDBCConnection.java:201 - this getConnection method makes a call to DatabaseaConnection.getConnection
  2. DatabaseConnection.java:150 - there are two important calls here. It looks like it is actually making two sockets.
    1. The first connection is to authenticate the user. From this we can get the server level/version and also the password level - this is needed for later.
    2. This calls SignonConnection.Java:230 (getConnection) which then calls another overload at line line 242.
    3. From here it then creates a new instance of SignonConnection, calls the authenticate method (like 45), passing in the user/password - returning the connection.
    4. The authentication method is actually what is used to determine the system CCSID, which is then used for future connections (including future database connections)
  3. Then at DatabaseConnection.java:150 will call another overload method. But notice how it is passing in the conn.getInfo() returning object as a parameter. That object (SystemInfo, from SignonConnection:120) contains info like password level, ccsid and other things.
  4. The overload method, getConnection at DatabaseConnection.java:176, creates yet another socket (line 184).
    1. The library also uses its own class called HostInputStream to read and write to streams.
  5. At DatabaseConnection.java:199 is where it calls the connect method. Since DatabaseConnection inherits HostServerConnection, the method can be found at HostServerConnection.java:198.
    1. It first does some enchanting of seeds/bytes before actually encoding the username and password, using their own retrospective methods: getUserBytes and getPasswordBytes (note that the password level is passed in!)
    2. Note that both the username and password are both passed in to the server as 37 if the password level is less than two - otherwise unicode. See Conv.java for all that code.
    3. Note that the password is also encoded as either SHA or DES. If the password level is 2 or more, DES is used.
    4. After that, all the info is sent over the socket. We then check for errors using the getReturnCodeMessage function and also grab the job name before returning the job name.
  6. Back in JDBCConnection.java:206, we then set some attributes in a new instead of the class DatabaseServerAttributes, which in return calls DatabaseConnection.setServerAttributes
  7. We now have successfully created a socket connection to Db2 for i.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment