Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2009
    Posts
    6

    Unanswered: Communication between JAVA and DB2 HowTo?

    Hello, i am new to Java and DB2. If my posting is just too stupid, please dont laugh that loud.

    Situation:
    There is my PC with a JAVA-application
    There is another PC running a DB2.
    Both PCs stand in different buildings, connected via VPN.

    An IBM DB2 client runs on my PC.
    The JAVA-application ist connected to the DB2, i can send SQL-queries and receive results.

    Everything fine until now...

    The Problem is:
    I want to send other commands to the DB2 like "get snapshot for all on ds2"
    But that doesnt work!
    Here is my code:
    Code:
       Connection con = null; 
              try 
              { 
             con = DriverManager.getConnection( "jdbc:db2:DS2", "**username**", "**password**" );
             Statement stmt = con.createStatement(); 
             ResultSet rs = stmt.executeQuery( "get snapshot for all on ds2" );
    I get this error: "com.ibm.db2.jcc.b.SqlException: [jcc][10103][10941][3.50.152] Die Methode executeQuery kann nicht zur Aktualisierung verwendet werden. ERRORCODE=-4476, SQLSTATE=null
    "

    This is german. It means "you cant update with executeQuery"...
    BUT: I dont update my Database. I just want to read some Monitor-datas...


    Help! How to read monitor-data from DS2?

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    You cannot run db2 commands using jdbc. What db2 version and OS are you using?

    Andy

  3. #3
    Join Date
    Feb 2009
    Posts
    6
    My PC is Windows XP.
    The other PC running DB2 is Linux. DB2 Version 9.5.0.808

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    You can use jdbc to query the admin views and functions and that will get you the snapshot info.

    Andy

  5. #5
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  6. #6
    Join Date
    Feb 2009
    Posts
    6
    Thank you!
    I will search, which admin view contains the required information.

    But does this work for ALTER TABLESPACE too?
    I want to change some DB2-Parameters like prefetchsize.

  7. #7
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    I believe that ALTERTABLESPACE is regulare SQL and can be executed through jdbc. To change parameters, look at the ADMIN_CMD stored Procedure.

    Andy

  8. #8
    Join Date
    Feb 2009
    Posts
    6
    thank you! I wil try that.

  9. #9
    Join Date
    Feb 2009
    Posts
    6
    Hello,
    meanwhile i could get the required Information by query an admin view. That worked fine. example:
    ResultSet rs = stmt.executeQuery( "SELECT sum(PREFETCH_WAIT_TIME) AS TIME FROM SYSIBMADM.SNAPAPPL" );
    ...to query the current PREFETCH_WAIT_TIME...

    To change Prefetchsize, do this:
    int rs = stmt.executeUpdate( "ALTER TABLESPACE USERSPACE1 PREFETCHSIZE 128" );

    executeUpdate instead executeQuery

    Just, if someone else has the same problems!

Posting Permissions

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