Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    2

    Unanswered: 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 19:51.

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    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
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Jan 2012
    Posts
    2
    Thank you, Guy Przytula!

    I will try your idea.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •