java的db2连接问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1588687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:31:27  来源:igfitidea点击:

Db2 connection problem with java

javajdbcdb2db2-luw

提问by RishiPatel

I am having problem with DB2. I just installed the db2 as a db2admin and with a password. When i try to connect to database it is success full and while running any simple select query it give me following error:-

我在使用 DB2 时遇到问题。我刚刚将 db2 安装为 db2admin 并使用密码。当我尝试连接到数据库时,它完全成功,并且在运行任何简单的选择查询时,它给我以下错误:-

DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.LOGIN, DRIVER=3.57.82

DB2 SQL 错误:SQLCODE=-204,SQLSTATE=42704,SQLERRMC=DB2ADMIN.LOGIN,DRIVER=3.57.82

I have a database named onp and a table in it called 'login' in which there is one table called 'login' with two fields username and password.

我有一个名为 onp 的数据库和一个名为“登录”的表,其中有一个名为“登录”的表,其中包含两个字段用户名和密码。

Query that i am running

查询我正在运行

  1. Select * from login; gives me error
  1. 从登录中选择*;给我错误

DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.LOGIN, DRIVER=3.57.82

DB2 SQL 错误:SQLCODE=-204,SQLSTATE=42704,SQLERRMC=DB2ADMIN.LOGIN,DRIVER=3.57.82

  1. Select * from system.login; gives me error:- (//system is schema name)
  1. 从 system.login 中选择 *;给我错误:-(//系统是架构名称)

DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=DB2ADMIN;SELECT;SYSTEM.LOGIN, DRIVER=3.57.82

DB2 SQL 错误:SQLCODE=-551,SQLSTATE=42501,SQLERRMC=DB2ADMIN;SELECT;SYSTEM.LOGIN,DRIVER=3.57.82

I have tried all the resources on the net and exhausted completely. Please help me

我已经尝试了网络上的所有资源并且完全耗尽。请帮我

采纳答案by Powerlord

I don't know a lot about DB2, but looking up the error codes...

我对 DB2 了解不多,但查找错误代码...

The first error is because you didn't specify a schema, so it couldn't find the login table.

第一个错误是因为您没有指定架构,因此找不到登录表。

SQLCODE -204 Object not defined to DB2

SQLCODE -204 对象未定义到 DB2

DB2 apparently requires you to specify the schema name or it looks in the schema with the same name as your login user.

DB2 显然要求您指定模式名称,否则它会在与您的登录用户同名的模式中查找。

You must use SET SCHEMAor fully qualify the table name.

您必须使用SET SCHEMA或完全限定表名。

The second error is because you don't have the privileges to perform that select:

第二个错误是因为您没有执行该选择的权限:

SQLCODE -551, Error: DOES NOT HAVE THE PRIVILEGE TO PERFORM OPERATION ON OBJECT

SQLCODE -551,错误:没有对对象执行操作的权限

I'm not sure why the db2admin user wouldn't be able to select from this table...

我不知道为什么 db2admin 用户不能从这个表中选择...

Resources:
List of DB2 SQLCODEs

资源:
DB2 SQLCODE 列表

回答by Kishore

You can also resolve the issue as:

您还可以通过以下方式解决问题:

Just give the proper authority to the user by which you are connection to DB2.

只需为您连接到 DB2 的用户授予适当的权限即可。

回答by zawhtut

SQL CODE 551 occurred because the connecting user does not have privileges to perform operations.

发生 SQL CODE 551 是因为连接用户没有执行操作的权限。

Go to Control Center - Go to User Group and Object and select DB2ADMIN(assume this user is the one use to connect to DB2)

转到控制中心 - 转到用户组和对象并选择 DB2ADMIN(假设此用户是连接到 DB2 的用户)

enter image description here

在此处输入图片说明

Check all the check box as the following

选中所有复选框,如下所示

enter image description here

在此处输入图片说明

Grant Schema access to the user enter image description here

授予用户架构访问权限 在此处输入图片说明

Grant Tables access to the user enter image description here

向用户授予 Tables 访问权限 在此处输入图片说明

回答by ilias

I had the same problem and i resolved it by adding Schema in my entity :

我遇到了同样的问题,我通过在我的实体中添加架构来解决它:

@Entity
@Table(name="MyTable", schema="MySchemaName")
public class MyClass implements Serializable {
...
}