DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704

前端 未结 5 957
庸人自扰
庸人自扰 2020-12-19 01:58

I created local database in DB2 called \"TestDB\" then I created table called \"TestTable\".
I found that the table is put under schema name is

5条回答
  •  悲&欢浪女
    2020-12-19 02:15

    The problem was The table I created in db2 has schema name "yasmin"
    I used username and password "db2admin/db2admin" In JDBC connection
    so it search for the table in this schema "db2admin"
    so I need to set the schema to be "yasmin"
    so I added the following lines of code after creating the connection

                String schemaName="yasmin";
                if (schemaName != null && schemaName.length() != 0) {
    
                try {
                    statement = connection.createStatement();
                    statement.executeUpdate("set current sqlid = " + schemaName);
                    System.out.println("The schema is set successfully.");
                } catch (SQLException exception) {
                    exception.printStackTrace();
    
                }
    

    and grant db2admin all privilages on this table in db2

    1-Right click on the table choose privilages
    2-Click on "Add user" button
    3-then write the username "db2admin" and click "apply" button
    4-Then select the user you just add and click "gtant all" button

    Now he can see the table.

    Many Thanks @Mark Rotteveel and @bhamby for your help.

提交回复
热议问题