If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Cannot read DB2 database with Java code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-12, 17:59
bobchen bobchen is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Cannot read DB2 database with Java code

Hi,

I have installed DB2 community version on Linux. A database with the name of "userabc" has been created. I log in as "userabc" user, run "db2" command, "CONNECT TO USERABC" and run the following command:

CREATE TABLE "USERABC"."TESTCOM" (DEPTNO CHAR(3) NOT NULL, DEPTNAME VARCHAR(36) NOT NULL, MGRNO CHAR(6), ADMRDEPT CHAR(3) NOT NULL, PRIMARY KEY(DEPTNO))

Then I run "SELECT * FROM USERABC.TESTCOM" and the command work.

Then I run "TERMINATE" and quit the DB2 server.

After that I write a Java program to read data from that "TESTCOM" table. The Java code is as follows:

conn = DriverManager.getConnection("jdbc:db2://localhost:50000/USERABC","userabc","passwd");
...
String queryStr = "SELECT * FROM USERABC.TESTCOM";

The code does not work. The error message is as follows:


$ java DB2Connect
DB2 driver is loaded successfully
DB2 Database Connected
SELECT * FROM USERABC.TESTCOM
com.ibm.db2.jcc.am.ro: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=USERABC.TESTCOM, DRIVER=3.58.82
at com.ibm.db2.jcc.am.ed.a(ed.java:676)
at com.ibm.db2.jcc.am.ed.a(ed.java:60)
at com.ibm.db2.jcc.am.ed.a(ed.java:127)
at com.ibm.db2.jcc.am.tm.c(tm.java:2523)
at com.ibm.db2.jcc.am.tm.d(tm.java:2511)
at com.ibm.db2.jcc.am.tm.a(tm.java:1991)
at com.ibm.db2.jcc.t4.fb.g(fb.java:140)
at com.ibm.db2.jcc.t4.fb.a(fb.java:40)
at com.ibm.db2.jcc.t4.t.a(t.java:32)
at com.ibm.db2.jcc.t4.ub.i(ub.java:135)
at com.ibm.db2.jcc.am.tm.fb(tm.java:1962)
at com.ibm.db2.jcc.am.um.nc(um.java:2989)
at com.ibm.db2.jcc.am.um.b(um.java:3760)
at com.ibm.db2.jcc.am.um.Zb(um.java:673)
at com.ibm.db2.jcc.am.um.executeQuery(um.java:647)
at DB2Connect.main(DB2Connect.java:52)



However, when I run the following code, it works.


conn = DriverManager.getConnection("jdbc:db2://localhost:50000/USERABC","userabc","passwd");
...
String queryStr = "SELECT * from syscat.tables";



Your help is highly appreciated!

Last edited by bobchen; 01-23-12 at 18:51.
Reply With Quote
  #2 (permalink)  
Old 01-24-12, 02:49
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
create a small test program that will list tables for this schema or list all distinct schema
there must be an error - or connected to wrong database
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 01-24-12, 02:53
bobchen bobchen is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Thank you, Guy Przytula!

I will try your idea.
Reply With Quote
Reply

Tags
db2, read

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On