18 jul 2009

com.ibm.db2.jcc.am.io: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704

I am taking a master in Software Engineering, our teacher has asked us to use different kinds of DB Manager Systems (DBMS). I tried with IBM DB2, and got different annoying problems.
One of them is the

com.ibm.db2.jcc.am.io: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704

I found some solutions with Google, but none of them helped me in a direct way. This is my code:
Class.forName( "com.ibm.db2.jcc.DB2Driver" );
Connection con = DriverManager.getConnection( "jdbc:db2://server.com:50000/POO", "user", "pass" );

Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM test");

And the error in the last line. We need to indicate the Schema of the table, in other DBMSs it is not needed, but it looks like DB2 does.
So I went to the DB Control Center and I saw that there was a Schema name of the table that I have not noted, then the fix is quick:

ResultSet res = st.executeQuery("SELECT * FROM schema.test");

The schema name of the table was "sergio", so I wrote sergio.test.

ResultSet res = st.executeQuery("SELECT * FROM sergio.test");

And all was solved.


Resources:
http://www.dbtalk.net/ibm-software-db2-udb/db2-error-db2-sql-error-401235.html

No hay comentarios.: