Sample Header Ad - 728x90

JDBC using DataSource, DB2 and Kerberos

0 votes
0 answers
116 views
I am trying to set up a JDBC using DataSource interface, DB2 database and Kerberos for authentication. I am using IBMs documentation which refers in *Kerberos security with no user ID or password* [link here](https://www.ibm.com/docs/en/db2/11.5?topic=sudsdjs-kerberos-security-under-data-server-driver-jdbc-sqlj#imjcc_cjvjcskb__title__3) . **Code block for DataSource**
DB2SimpleDataSource dataSource = new DB2SimpleDataSource();
            dataSource.setDriverType(4);
            dataSource.setServerName("server");
            dataSource.setPortNumber(portnumber);
            dataSource.setDatabaseName("database name");
            dataSource.setSslConnection(true);
            dataSource.setClientProgramName("program name");
            dataSource.setRetrieveMessagesFromServerOnGetMessage(true);
            dataSource.setSecurityMechanism(dataSource.KERBEROS_SECURITY);
I have the following error in my console: **Error message**
com.ibm.db2.jcc.am.SqlException: [jcc][t4][4.19.49] Unexpected Throwable caught: class com.ibm.db2.jcc.am.le (in unnamed module @0x49097b5d) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x49097b5d. ERRORCODE=-4228, SQLSTATE=null
    at com.ibm.db2.jcc.am.kd.a(Unknown Source)
    at com.ibm.db2.jcc.am.kd.a(Unknown Source)
    at com.ibm.db2.jcc.am.kd.a(Unknown Source)
    at com.ibm.db2.jcc.t4.b.b(Unknown Source)
    at com.ibm.db2.jcc.t4.b.a(Unknown Source)
    at com.ibm.db2.jcc.t4.b.a(Unknown Source)
    at com.ibm.db2.jcc.t4.b.a(Unknown Source)
    at com.ibm.db2.jcc.t4.b.(Unknown Source)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
    at test.connection.TestDbConnectionDataSource.main(TestDbConnectionDataSource.java:81)
Caused by: java.lang.IllegalAccessError: class com.ibm.db2.jcc.am.le (in unnamed module @0x49097b5d) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x49097b5d
    at com.ibm.db2.jcc.am.le.a(Unknown Source)
    at com.ibm.db2.jcc.am.le.a(Unknown Source)
    at com.ibm.db2.jcc.t4.b.a(Unknown Source)
I am not using the dataSource.setKerberosServerPrincipal("sample/srvlsj.ibm.com@SRVLSJ.SJ.IBM.COM"); which refers in IBM doc. Moreover, I am using many **realm** which I have to replace the @SRVLSJ.SJ.IBM.COM. For this reason I am using the System.setProperty("java.security.krb5.conf", "path\krb5.conf"); The adove error I can resolve this error if I use in VM arguments this: --add-exports java.base/sun.security.action=ALL-UNNAMED. But, I am searching a way to still work without this in VM arguments. Last details. I am using com.ibm.db2.jcc.DB2SimpleDataSource interface. The version of DB2 is 4.19.49, jdk 17.0.6, Kerberos 5.
Asked by bagb (1 rep)
Jan 15, 2024, 10:17 AM
Last activity: Jan 15, 2024, 12:42 PM