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 > Communication between JAVA and DB2 HowTo?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-09, 10:20
Andreas I. Andreas I. is offline
Registered User
 
Join Date: Feb 2009
Posts: 6
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?
Reply With Quote
  #2 (permalink)  
Old 02-16-09, 11:23
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You cannot run db2 commands using jdbc. What db2 version and OS are you using?

Andy
Reply With Quote
  #3 (permalink)  
Old 02-16-09, 11:28
Andreas I. Andreas I. is offline
Registered User
 
Join Date: Feb 2009
Posts: 6
My PC is Windows XP.
The other PC running DB2 is Linux. DB2 Version 9.5.0.808
Reply With Quote
  #4 (permalink)  
Old 02-16-09, 11:35
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You can use jdbc to query the admin views and functions and that will get you the snapshot info.

Andy
Reply With Quote
  #5 (permalink)  
Old 02-16-09, 11:48
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #6 (permalink)  
Old 02-16-09, 11:52
Andreas I. Andreas I. is offline
Registered User
 
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.
Reply With Quote
  #7 (permalink)  
Old 02-16-09, 12:02
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I believe that ALTERTABLESPACE is regulare SQL and can be executed through jdbc. To change parameters, look at the ADMIN_CMD stored Procedure.

Andy
Reply With Quote
  #8 (permalink)  
Old 02-16-09, 12:13
Andreas I. Andreas I. is offline
Registered User
 
Join Date: Feb 2009
Posts: 6
thank you! I wil try that.
Reply With Quote
  #9 (permalink)  
Old 02-17-09, 12:07
Andreas I. Andreas I. is offline
Registered User
 
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!
Reply With Quote
Reply

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