0

I have installed DB2 on my local machine and created a table Users with a column Name.

From my portlets I am executing a simple select statement:

    Class.forName("com.ibm.db2.jcc.DB2Driver");
    String dburl = "jdbc:db2://localhost:50001/Portlets";
    conn = DriverManager.getConnection(dburl,"db2admin","password");
    String selectTableSQL = "SELECT Name from Users";
    statement = conn.createStatement();
ResultSet rs = statement.executeQuery(selectTableSQL);

when i execute this i get the following exception:

com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.USERS, DRIVER=3.62.56.

I dont understand why I am getting this exception. There is nothing much in the stack trace as well.

1 Answer 1

3

The SQLCODE in your message is what tells you the actual error message. -204 is the error you are looking for. If you cross-reference the Information Center article about -204, you will see the following message:

name is an undefined name.

And if you look back at your exception, you see name = DB2ADMIN.USERS (the SQLERRMC field).

My guess is that you aren't finding anything because you forgot to append a Schema to your table (the DB2ADMIN part was assumed in the error message because that's your login name).

Sign up to request clarification or add additional context in comments.

1 Comment

I actually resolved the issue. Its strange that I craeted a table with my domain name Sachin.Jain but then I granted all the permissions to db2admin like select insert sql commands and even then it was not able to access the database. So i finally logged in with db2admin user and then created the table and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.