問題描述
我正在嘗試使用 DB2JDBC Type4 驅動程序配置 DB2 連接.但是我收到了這個錯誤.
I am trying to configure DB2 connection with DB2JDBC Type4 drivers. But I am getting this error.
線程main"中的異常com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException:[jcc][t4][201][11237][3.64.104] 連接授權失敗發生了.原因:不支持安全機制.錯誤代碼=-4214,SQLSTATE=28000
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
我的代碼是
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 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)
我也嘗試過 IBM Data Server Driver for JDBC and SQLJ 支持的這些機制
I also have tried these supported mechanisms by IBM Data Server Driver for JDBC and SQLJ
-CLIENT
-SERVER
-SERVER_ENCRYPT
-DATA_ENCRYPT
-KERBEROS
-GSSPLUGIN
-KRB_SERVER_ENCRYPT
-GSS_SERVER_ENCRYPT
為了避免加密問題,我們將此應用程序部署到 linux 機器上.所以如果需要安全連接,但那里發生同樣的錯誤.
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.
我使用的是DB2 JDBC Driver版本v10.1fp1_jdbc_sqlj
,我也試過9.5
和9.1
和db2jcc4.jar
文件用于此目的.
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.
我也嘗試過使用 type 2
驅動程序,但在這種情況下 COM.ibm.db2.jdbc.app.DB2Driver
會出現 ClassNotFound 錯誤.找不到類.
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.
但到目前為止沒有任何效果.任何幫助表示贊賞.一個多星期以來,我一直在努力解決這個問題.
But nothing worked so far. Any help is appreciated. I am struggling with this problem over a week.
推薦答案
現在可以了.問題出在 DB2 上.您必須確保您的環境變量指向正確的文件夾.所以一定要做到以下幾點:
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:
- 每次更改或對環境變量進行所有更改后都必須重新啟動計算機.
- 確保您使用的是
JDBC Type 2
驅動程序.除非您的 DBA 要求,否則不要選擇Type 4
.
- 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 forType 4
unless asked by your DBA.
將幫助您確保您的代碼能夠與 Windows JDBC 驅動程序交互
Will help you to make sure that your code will be able to interact with Windows JDBC Drivers
PATH=C:Program FilesIBMSQLLIBBINdb2jdbc.dll
LIB
將幫助您的代碼讀取正確的庫.即 COM.ibm.db2.jdbc.app.DB2Driver
LIB
will help your code to read right libraries. i.e COM.ibm.db2.jdbc.app.DB2Driver
LIB=;C:PROGRA~1IBMSQLLIBLIB
類路徑:
ClassPath = .;C:PROGRA~1IBMSQLLIBjavadb2java.jar;
C:PROGRA~1IBMSQLLIBjavadb2jcc.jar;C:PROGRA~1IBMSQLLIBjavasqlj.zip;
C:PROGRA~1IBMSQLLIBBINdb2jdbc.dll;
C:PROGRA~1IBMSQLLIBjavadb2jcc.jar;
C:PROGRA~1IBMSQLLIBjavasqlj.zip;
C:PROGRA~1IBMSQLLIBjavadb2jcc_license_cu.jar;
C:PROGRA~1IBMSQLLIBjavadb2java.jar;
C:PROGRA~1IBMSQLLIBBIN;C:PROGRA~1IBMSQLLIBjavajdk;
這篇關于發生 DB2 連接授權失敗原因:Java 中不支持安全機制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!