Java 通过JDBC连接到DB2时的用户和密码
我正在尝试连接到本地DB210.5Express-C服务器。这是一个测试环境,所以我不关心安全性 我能够连接到命令行处理器(在Windows上运行),并更改了Java 通过JDBC连接到DB2时的用户和密码,java,jdbc,db2,Java,Jdbc,Db2,我正在尝试连接到本地DB210.5Express-C服务器。这是一个测试环境,所以我不关心安全性 我能够连接到命令行处理器(在Windows上运行),并更改了AUTHENTICATION=CLIENT和TRUST\u ALLCLNTS=YES的配置设置。当时我希望能够在没有身份验证的情况下进行连接(我重新启动了DB2服务),但仍然出现了一个错误 当我尝试在没有用户名/密码的情况下连接时 jdbc:db2://localhost:50000/test 我得到错误:com.ibm.db2.jcc.
AUTHENTICATION=CLIENT
和TRUST\u ALLCLNTS=YES
的配置设置。当时我希望能够在没有身份验证的情况下进行连接(我重新启动了DB2服务),但仍然出现了一个错误
当我尝试在没有用户名/密码的情况下连接时
jdbc:db2://localhost:50000/test
我得到错误:com.ibm.db2.jcc.am.SqlSyntaxErrorException:[jcc][t4][10205][11234][4.14.146]不支持空用户ID。ERRORCODE=-4461,SQLSTATE=42815
当我尝试添加“伪造”用户/密码时(因为我不知道如何设置或重置凭据),例如
我得到错误:com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException:[jcc][t4][201][11237][4.14.146]发生连接授权失败。原因:不支持安全机制。ERRORCODE=-4214,SQLSTATE=28000
如何使用JDBC进行连接
DB2配置如下:
db2 get dbm cfg
Database Manager Configuration Node type = Database Server with local and remote clients Database manager configuration release level = 0x1000 CPU speed (millisec/instruction) (CPUSPEED) = 1.023413e-007 Max number of concurrently active databases (NUMDB) = 32
Federated Database System Support (FEDERATED) = NO
Transaction processor monitor name (TP_MON_NAME) =
Default charge-back account (DFT_ACCOUNT_STR) =
Java Development Kit installation path (JDK_PATH) = C:\PROGRA~1\IBM\SQLLIB\java\jdk Diagnostic error capture level (DIAGLEVEL) = 3
Notify Level (NOTIFYLEVEL) = 3
Diagnostic data directory path (DIAGPATH) = E:\Data\DB2\\IBM\DB2\DB2COPY1\DB2\
Current member resolved DIAGPATH = E:\Data\DB2\\IBM\DB2\DB2COPY1\DB2\
Alternate diagnostic data directory path (ALT_DIAGPATH) =
Current member resolved ALT_DIAGPATH =
Size of rotating db2diag & notify logs (MB) (DIAGSIZE) = 0 Default database monitor switches
Buffer pool (DFT_MON_BUFPOOL) = OFF
Lock (DFT_MON_LOCK) = OFF
Sort (DFT_MON_SORT) = OFF
Statement (DFT_MON_STMT) = OFF
Table (DFT_MON_TABLE) = OFF
Timestamp (DFT_MON_TIMESTAMP) = ON
Unit of work (DFT_MON_UOW) = OFF
Monitor health of instance and databases (HEALTH_MON) = OFF SYSADM group name (SYSADM_GROUP) =
SYSCTRL group name (SYSCTRL_GROUP) =
SYSMAINT group name (SYSMAINT_GROUP) =
SYSMON group name (SYSMON_GROUP) =
Client Userid-Password Plugin (CLNT_PW_PLUGIN) =
Client Kerberos Plugin (CLNT_KRB_PLUGIN) = IBMkrb5
Group Plugin (GROUP_PLUGIN) =
GSS Plugin for Local Authorization (LOCAL_GSSPLUGIN) =
Server Plugin Mode (SRV_PLUGIN_MODE) = UNFENCED
Server List of GSS Plugins (SRVCON_GSSPLUGIN_LIST) =
Server Userid-Password Plugin (SRVCON_PW_PLUGIN) =
Server Connection Authentication (SRVCON_AUTH) = NOT_SPECIFIED
Cluster manager =
Database manager authentication (AUTHENTICATION) = CLIENT
Alternate authentication (ALTERNATE_AUTH_ENC) = NOT_SPECIFIED
Cataloging allowed without authority (CATALOG_NOAUTH) = YES
Trust all clients (TRUST_ALLCLNTS) = YES
Trusted client authentication (TRUST_CLNTAUTH) = CLIENT
Bypass federated authentication (FED_NOAUTH) = YES Default database path (DFTDBPATH) = C: Database monitor heap size (4KB) (MON_HEAP_SZ) = AUTOMATIC(66)
Java Virtual Machine heap size (4KB) (JAVA_HEAP_SZ) = 2048
Audit buffer size (4KB) (AUDIT_BUF_SZ) = 0
Global instance memory (4KB) (INSTANCE_MEMORY) = AUTOMATIC(3592673)
Member instance memory (4KB) = GLOBAL
Agent stack size (AGENT_STACK_SZ) = 16
Sort heap threshold (4KB) (SHEAPTHRES) = 0 Directory cache support (DIR_CACHE) = YES Application support layer heap size (4KB) (ASLHEAPSZ) = 15
Max requester I/O block size (bytes) (RQRIOBLK) = 65535
Workload impact by throttled utilities(UTIL_IMPACT_LIM) = 10 Priority of agents (AGENTPRI) = SYSTEM
Agent pool size (NUM_POOLAGENTS) = AUTOMATIC(100)
Initial number of agents in pool (NUM_INITAGENTS) = 0
Max number of coordinating agents (MAX_COORDAGENTS) = AUTOMATIC(200)
Max number of client connections (MAX_CONNECTIONS) = AUTOMATIC(MAX_COORDAGENTS) Keep fenced process (KEEPFENCED) = YES
Number of pooled fenced processes (FENCED_POOL) = AUTOMATIC(MAX_COORDAGENTS)
Initial number of fenced processes (NUM_INITFENCED) = 0 Index re-creation time and redo index build (INDEXREC) = RESTART Transaction manager database name (TM_DATABASE) = 1ST_CONN
Transaction resync interval (sec) (RESYNC_INTERVAL) = 180 SPM name (SPM_NAME) = WORKS12
SPM log size (SPM_LOG_FILE_SZ) = 256
SPM resync agent limit (SPM_MAX_RESYNC) = 20
SPM log path (SPM_LOG_PATH) =
TCP/IP Service name (SVCENAME) = db2c_DB2
Discovery mode (DISCOVER) = SEARCH
Discover server instance (DISCOVER_INST) = ENABLE SSL server keydb file (SSL_SVR_KEYDB) =
SSL server stash file (SSL_SVR_STASH) =
SSL server certificate label (SSL_SVR_LABEL) =
SSL service name (SSL_SVCENAME) =
SSL cipher specs (SSL_CIPHERSPECS) =
SSL versions (SSL_VERSIONS) =
SSL client keydb file (SSL_CLNT_KEYDB) =
SSL client stash file (SSL_CLNT_STASH) =
Maximum query degree of parallelism (MAX_QUERYDEGREE) = ANY
Enable intra-partition parallelism (INTRA_PARALLEL) = NO No. of int. communication buffers(4KB)(FCM_NUM_BUFFERS) = AUTOMATIC(1024)
No. of int. communication channels (FCM_NUM_CHANNELS) = AUTOMATIC(512)
db2start/db2stop timeout (min) (START_STOP_TIME) = 10 WLM dispatcher enabled (WLM_DISPATCHER) = NO WLM dispatcher concurrency (WLM_DISP_CONCUR) = COMPUTED WLM dispatcher CPU shares enabled (WLM_DISP_CPU_SHARES) = NO WLM dispatcher min. utilization (%) (WLM_DISP_MIN_UTIL) = 5 Communication buffer exit library list (COMM_EXIT_LIST) =
Current effective arch level (CUR_EFF_ARCH_LVL) = V:10 R:5 M:0 F:5 I:0 SB:0
Current effective code level (CUR_EFF_CODE_LVL) = V:10 R:5 M:0 F:5 I:0 SB:0 Keystore type (KEYSTORE_TYPE) = NONE
Keystore location (KEYSTORE_LOCATION) =
您需要使用JDBC类型2 URL(
JDBC:db2:test
),而不是您正在使用的类型4 URL。您可以使用空用户名/密码
由于您的应用程序与数据库服务器在同一台计算机上运行,因此您甚至不需要设置
AUTHENTICATION=CLIENT
或TRUST\u ALLCLNTS=YES
,我没有WebSphere,也没有WebSphere管理控制台,当我尝试确保DriverManager.getConnection()没有错误时。但是我尝试使用Statement.executeQuery()
或Statement.executeUpdate()
执行的任何查询都会抛出ArrayIndexOutOfBoundsException
:java.lang.ArrayIndexOutOfBoundsException位于java.lang.System.arraycopy(本机方法)位于com.ibm.db2.jcc.t4.y.a(y.java:102)位于com.ibm.db2.jcc.t4.y.a(y.java:150)com.ibm.db2.jcc.uw.uwrepy.b(uwrepy.java:62)com.ibm.db2.jcc.t4.y.c(y.java:360)com.ibm.db2.jcc.t4.y.d(y.java:375)com.ibm.db2.jcc.t4.y.f(y.java:646)com.ibm.db2.jcc.t4.z.ic(z.java:4622)
您的JDBC驱动程序和客户端之间似乎不匹配。您是否使用Express-C安装中包含的db2jcc.jar文件(即C:\Program Files\IBM\SQLLIB\java
),或者您下载的其他驱动程序?我从IBM网站下载的另一个驱动程序,实际上我使用了db2jcc4.jar
,这可能会导致与JDBC 2连接字符串不兼容。我将尝试使用您提到的驱动程序,并向您报告。
db2 get dbm cfg
Database Manager Configuration Node type = Database Server with local and remote clients Database manager configuration release level = 0x1000 CPU speed (millisec/instruction) (CPUSPEED) = 1.023413e-007 Max number of concurrently active databases (NUMDB) = 32
Federated Database System Support (FEDERATED) = NO
Transaction processor monitor name (TP_MON_NAME) =
Default charge-back account (DFT_ACCOUNT_STR) =
Java Development Kit installation path (JDK_PATH) = C:\PROGRA~1\IBM\SQLLIB\java\jdk Diagnostic error capture level (DIAGLEVEL) = 3
Notify Level (NOTIFYLEVEL) = 3
Diagnostic data directory path (DIAGPATH) = E:\Data\DB2\\IBM\DB2\DB2COPY1\DB2\
Current member resolved DIAGPATH = E:\Data\DB2\\IBM\DB2\DB2COPY1\DB2\
Alternate diagnostic data directory path (ALT_DIAGPATH) =
Current member resolved ALT_DIAGPATH =
Size of rotating db2diag & notify logs (MB) (DIAGSIZE) = 0 Default database monitor switches
Buffer pool (DFT_MON_BUFPOOL) = OFF
Lock (DFT_MON_LOCK) = OFF
Sort (DFT_MON_SORT) = OFF
Statement (DFT_MON_STMT) = OFF
Table (DFT_MON_TABLE) = OFF
Timestamp (DFT_MON_TIMESTAMP) = ON
Unit of work (DFT_MON_UOW) = OFF
Monitor health of instance and databases (HEALTH_MON) = OFF SYSADM group name (SYSADM_GROUP) =
SYSCTRL group name (SYSCTRL_GROUP) =
SYSMAINT group name (SYSMAINT_GROUP) =
SYSMON group name (SYSMON_GROUP) =
Client Userid-Password Plugin (CLNT_PW_PLUGIN) =
Client Kerberos Plugin (CLNT_KRB_PLUGIN) = IBMkrb5
Group Plugin (GROUP_PLUGIN) =
GSS Plugin for Local Authorization (LOCAL_GSSPLUGIN) =
Server Plugin Mode (SRV_PLUGIN_MODE) = UNFENCED
Server List of GSS Plugins (SRVCON_GSSPLUGIN_LIST) =
Server Userid-Password Plugin (SRVCON_PW_PLUGIN) =
Server Connection Authentication (SRVCON_AUTH) = NOT_SPECIFIED
Cluster manager =
Database manager authentication (AUTHENTICATION) = CLIENT
Alternate authentication (ALTERNATE_AUTH_ENC) = NOT_SPECIFIED
Cataloging allowed without authority (CATALOG_NOAUTH) = YES
Trust all clients (TRUST_ALLCLNTS) = YES
Trusted client authentication (TRUST_CLNTAUTH) = CLIENT
Bypass federated authentication (FED_NOAUTH) = YES Default database path (DFTDBPATH) = C: Database monitor heap size (4KB) (MON_HEAP_SZ) = AUTOMATIC(66)
Java Virtual Machine heap size (4KB) (JAVA_HEAP_SZ) = 2048
Audit buffer size (4KB) (AUDIT_BUF_SZ) = 0
Global instance memory (4KB) (INSTANCE_MEMORY) = AUTOMATIC(3592673)
Member instance memory (4KB) = GLOBAL
Agent stack size (AGENT_STACK_SZ) = 16
Sort heap threshold (4KB) (SHEAPTHRES) = 0 Directory cache support (DIR_CACHE) = YES Application support layer heap size (4KB) (ASLHEAPSZ) = 15
Max requester I/O block size (bytes) (RQRIOBLK) = 65535
Workload impact by throttled utilities(UTIL_IMPACT_LIM) = 10 Priority of agents (AGENTPRI) = SYSTEM
Agent pool size (NUM_POOLAGENTS) = AUTOMATIC(100)
Initial number of agents in pool (NUM_INITAGENTS) = 0
Max number of coordinating agents (MAX_COORDAGENTS) = AUTOMATIC(200)
Max number of client connections (MAX_CONNECTIONS) = AUTOMATIC(MAX_COORDAGENTS) Keep fenced process (KEEPFENCED) = YES
Number of pooled fenced processes (FENCED_POOL) = AUTOMATIC(MAX_COORDAGENTS)
Initial number of fenced processes (NUM_INITFENCED) = 0 Index re-creation time and redo index build (INDEXREC) = RESTART Transaction manager database name (TM_DATABASE) = 1ST_CONN
Transaction resync interval (sec) (RESYNC_INTERVAL) = 180 SPM name (SPM_NAME) = WORKS12
SPM log size (SPM_LOG_FILE_SZ) = 256
SPM resync agent limit (SPM_MAX_RESYNC) = 20
SPM log path (SPM_LOG_PATH) =
TCP/IP Service name (SVCENAME) = db2c_DB2
Discovery mode (DISCOVER) = SEARCH
Discover server instance (DISCOVER_INST) = ENABLE SSL server keydb file (SSL_SVR_KEYDB) =
SSL server stash file (SSL_SVR_STASH) =
SSL server certificate label (SSL_SVR_LABEL) =
SSL service name (SSL_SVCENAME) =
SSL cipher specs (SSL_CIPHERSPECS) =
SSL versions (SSL_VERSIONS) =
SSL client keydb file (SSL_CLNT_KEYDB) =
SSL client stash file (SSL_CLNT_STASH) =
Maximum query degree of parallelism (MAX_QUERYDEGREE) = ANY
Enable intra-partition parallelism (INTRA_PARALLEL) = NO No. of int. communication buffers(4KB)(FCM_NUM_BUFFERS) = AUTOMATIC(1024)
No. of int. communication channels (FCM_NUM_CHANNELS) = AUTOMATIC(512)
db2start/db2stop timeout (min) (START_STOP_TIME) = 10 WLM dispatcher enabled (WLM_DISPATCHER) = NO WLM dispatcher concurrency (WLM_DISP_CONCUR) = COMPUTED WLM dispatcher CPU shares enabled (WLM_DISP_CPU_SHARES) = NO WLM dispatcher min. utilization (%) (WLM_DISP_MIN_UTIL) = 5 Communication buffer exit library list (COMM_EXIT_LIST) =
Current effective arch level (CUR_EFF_ARCH_LVL) = V:10 R:5 M:0 F:5 I:0 SB:0
Current effective code level (CUR_EFF_CODE_LVL) = V:10 R:5 M:0 F:5 I:0 SB:0 Keystore type (KEYSTORE_TYPE) = NONE
Keystore location (KEYSTORE_LOCATION) =