DB2连接授权Faliure发生的原因:Java中不支持的安全机制。

时间:2022-10-02 23:55:23

I am trying to configure DB2 connection with DB2JDBC Type4 drivers. But I am getting this error.

我正在尝试用DB2JDBC Type4驱动程序配置DB2连接。但是我得到了这个错误。

Exception in thread "main" com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException: [jcc][t4][201][11237][3.64.104] Connection authorization failure occurred. Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000

在线程“main”com.ibm.db2.jcc.am中异常。SqlInvalidAuthorizationSpecException: [jcc][t4][201][11237][3.64.104]连接授权失败。原因:不支持安全机制。ERRORCODE = -4214,SQLSTATE = 28000

My code is

我的代码是

public Connection getConnection() throws ClassNotFoundException, InstantiationException,
                                         IllegalAccessException, SQLException{

   Driver driver = (Driver) Class.forName ( "com.ibm.db2.jcc.DB2Driver" ).newInstance(); 
  DriverManager.registerDriver(driver);
  Connection  connection = DriverManager.getConnection("jdbc:db2://hostname:portnumber
                                           /DBName", "username","password" );
    System.out.println( "From DAO, connection obtained " );
    return connection;  
}

Exception log:

异常日志:

Exception in thread "main" com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException:
[jcc][t4][201][11237][3.64.104] Connection authorization failure occurred. 
Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000
    at com.ibm.db2.jcc.am.bd.a(bd.java:677)
    at com.ibm.db2.jcc.am.bd.a(bd.java:60)
    at com.ibm.db2.jcc.am.bd.a(bd.java:120)
    at com.ibm.db2.jcc.t4.b.f(b.java:2389)
    at com.ibm.db2.jcc.t4.b.a(b.java:1712)
    at com.ibm.db2.jcc.t4.y.b(y.java:3612)
    at com.ibm.db2.jcc.t4.y.a(y.java:477)
    at com.ibm.db2.jcc.t4.y.a(y.java:117)
    at com.ibm.db2.jcc.t4.b.c(b.java:1350)
    at com.ibm.db2.jcc.t4.b.b(b.java:1221)
    at com.ibm.db2.jcc.t4.b.b(b.java:788)
    at com.ibm.db2.jcc.t4.b.a(b.java:760)
    at com.ibm.db2.jcc.t4.b.a(b.java:421)
    at com.ibm.db2.jcc.t4.b.a(b.java:396)
    at com.ibm.db2.jcc.t4.b.<init>(b.java:334)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:232)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:198)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:475)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:116)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.test.connection.DB2ConnectionFactory.getConnection(DB2ConnectionFactory.java:19
    at com.test.connection.ConnectionTest.main(ConnectionTest.java:18)

I also have tried these supported mechanisms by IBM Data Server Driver for JDBC and SQLJ

我还尝试了IBM Data Server驱动程序对JDBC和SQLJ的支持机制。

-CLIENT
-SERVER
-SERVER_ENCRYPT
-DATA_ENCRYPT
-KERBEROS
-GSSPLUGIN
-KRB_SERVER_ENCRYPT
-GSS_SERVER_ENCRYPT 

In order to avoid encryption problem we have deployed this application to linux box. SO in case need secure connection, but same error is occurring there.

为了避免加密问题,我们将此应用程序部署到linux框中。因此,在需要安全连接时,也会出现相同的错误。

I am using DB2 JDBC Driver version v10.1fp1_jdbc_sqlj, and I have also tried 9.5 and 9.1 and db2jcc4.jar file for this purpose.

我使用的是DB2 JDBC驱动程序v10.1fp1_jdbc_sqlj,我还尝试了9.5和9.1和db2jcc4。用于此目的的jar文件。

I have also tried it using type 2 drivers, but I am getting ClassNotFound error in that case COM.ibm.db2.jdbc.app.DB2Driver. class not found.

我也尝试过使用type 2驱动程序,但在这种情况下,我得到ClassNotFound错误。类没有找到。

But nothing worked so far. Any help is appreciated. I am struggling with this problem over a week.

但到目前为止,一切都不顺利。任何帮助都是感激。我在这个问题上挣扎了一个多星期。

3 个解决方案

#1


2  

It's working now. The problem was with DB2. You have to make sure that your environment variables point to the correct folders. So make sure to do the following:

现在的工作。问题在于DB2。您必须确保您的环境变量指向正确的文件夹。所以一定要做到以下几点:

  • Must reboot your machine after each change or after all the change you made to your environment variables.
  • 在每次更改后或在对环境变量进行了所有更改之后,必须重新启动您的计算机。
  • Make sure that you are using JDBC Type 2 drivers. Do not go for Type 4 unless asked by your DBA.
  • 确保您正在使用JDBC Type 2驱动程序。除非你的DBA要求,否则不要选择第4类。

Will help you to make sure that your code will be able to interact with Windows JDBC Drivers

将帮助您确保您的代码能够与Windows JDBC驱动程序交互?

PATH=C:\Program Files\IBM\SQLLIB\BIN\db2jdbc.dll

LIB will help your code to read right libraries. i.e COM.ibm.db2.jdbc.app.DB2Driver

LIB将帮助您的代码读取正确的库。我。e COM.ibm.db2.jdbc.app.DB2Driver

LIB=;C:\PROGRA~1\IBM\SQLLIB\LIB

ClassPath:

类路径:

ClassPath = .;C:\PROGRA~1\IBM\SQLLIB\java\db2java.jar;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\BIN\db2jdbc.dll;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;
C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cu.jar;
C:\PROGRA~1\IBM\SQLLIB\java\db2java.jar;
C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\java\jdk;

#2


0  

What authentication method is configured on the server? Is any custom authentication plugin used? You can obtain this information by running db2 get dbm cfg on the database server.

在服务器上配置了什么身份验证方法?是否使用了自定义身份验证插件?您可以通过在数据库服务器上运行db2 get dbm cfg来获得这些信息。

#3


0  

Type 2 driver is used when you have the Data server client installed in you machine. If you are running DB2 server in the same client machine, you can you Type 2 server.

当您在机器中安装了数据服务器客户端时,将使用Type 2驱动程序。如果您在同一个客户机机器上运行DB2服务器,那么您可以输入2个服务器。

Try to use the data server client, in order to catalog the remote database in your local machine, and try to establish a connection via "db2 connect to DBName" If you can establish the connection, you can do the same in Java. If you can't, you can chanqe the catalogation options, till found the right one. Once you have done that, you can connect to the remote database.

尝试使用数据服务器客户端,以便对本地计算机中的远程数据库进行编目,并尝试通过“db2 connect to DBName”建立连接,如果您可以建立连接,您可以在Java中进行相同的操作。如果不能,你可以查一下编目选项,直到找到正确的选项。完成之后,就可以连接到远程数据库了。

#1


2  

It's working now. The problem was with DB2. You have to make sure that your environment variables point to the correct folders. So make sure to do the following:

现在的工作。问题在于DB2。您必须确保您的环境变量指向正确的文件夹。所以一定要做到以下几点:

  • Must reboot your machine after each change or after all the change you made to your environment variables.
  • 在每次更改后或在对环境变量进行了所有更改之后,必须重新启动您的计算机。
  • Make sure that you are using JDBC Type 2 drivers. Do not go for Type 4 unless asked by your DBA.
  • 确保您正在使用JDBC Type 2驱动程序。除非你的DBA要求,否则不要选择第4类。

Will help you to make sure that your code will be able to interact with Windows JDBC Drivers

将帮助您确保您的代码能够与Windows JDBC驱动程序交互?

PATH=C:\Program Files\IBM\SQLLIB\BIN\db2jdbc.dll

LIB will help your code to read right libraries. i.e COM.ibm.db2.jdbc.app.DB2Driver

LIB将帮助您的代码读取正确的库。我。e COM.ibm.db2.jdbc.app.DB2Driver

LIB=;C:\PROGRA~1\IBM\SQLLIB\LIB

ClassPath:

类路径:

ClassPath = .;C:\PROGRA~1\IBM\SQLLIB\java\db2java.jar;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\BIN\db2jdbc.dll;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;
C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;
C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cu.jar;
C:\PROGRA~1\IBM\SQLLIB\java\db2java.jar;
C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\java\jdk;

#2


0  

What authentication method is configured on the server? Is any custom authentication plugin used? You can obtain this information by running db2 get dbm cfg on the database server.

在服务器上配置了什么身份验证方法?是否使用了自定义身份验证插件?您可以通过在数据库服务器上运行db2 get dbm cfg来获得这些信息。

#3


0  

Type 2 driver is used when you have the Data server client installed in you machine. If you are running DB2 server in the same client machine, you can you Type 2 server.

当您在机器中安装了数据服务器客户端时,将使用Type 2驱动程序。如果您在同一个客户机机器上运行DB2服务器,那么您可以输入2个服务器。

Try to use the data server client, in order to catalog the remote database in your local machine, and try to establish a connection via "db2 connect to DBName" If you can establish the connection, you can do the same in Java. If you can't, you can chanqe the catalogation options, till found the right one. Once you have done that, you can connect to the remote database.

尝试使用数据服务器客户端,以便对本地计算机中的远程数据库进行编目,并尝试通过“db2 connect to DBName”建立连接,如果您可以建立连接,您可以在Java中进行相同的操作。如果不能,你可以查一下编目选项,直到找到正确的选项。完成之后,就可以连接到远程数据库了。