Does anyone have an agent that accesses DB2 that works?

I have tried to my wits end to make an agent that works more than once. The first time it runs great, the second it coughs up the error “No Suitable Driver”

Outside of notes, the program runs repeatedly with no error.

Once its put in an Agent, it only runs once. I’ve tried this on 3 machines all can only run the agent once.

Ive read all the doc, searched the forum, and I am strongly starting to think this doesnt work at all.

db2jdbc.dll is in my notes program folder. Ive done this hundreds of times for other databases and they dont give me grief, but after 7 hours of working on this, where the same code works repeatedly for for mySQL but works only once for db2, I hope someone knows the answer.

Ive used the COM.ibm.db2.jdbc.app.DB2Driver with the proper URL of jdbc:db2:dbalias

Ive tried multiple ways of instantiating the driver

Ive even tried the com.ibm.jcc.DB2Driver which runs in Notes multiple times but gives a HUGE error on the server about “not allowed to access system properties” despite the agent security in both the server doc and the agentproperties is maxed out to run with full adminstration access.

So if anyone has an serverside agent that connects to db2 more than once, please let me know what the secret is.

my code mishmash after trying a dozen things is below:

import java.sql.*;

import java.util.Enumeration;

import java.util.Properties;

import COM.ibm.db2.jdbc.app.DB2Driver;

import lotus.domino.*;

/**

  • @author TS

*/

public class DB2ConnectDebug2 extends AgentBase {

static Driver drv=null;

static Connection db2_conn=null;



static String devdb2url="jdbc:db2:DBALIAS";



static String username="user";

static String password="password";

static Properties p=null;





public void NotesMain() {

	DB2ConnectDebug2.init();

}

public static void main(String[] args) {

	DB2ConnectDebug2.init();

}

public static void init() {

	



	

	DB2ConnectDebug2.reg();



	DB2ConnectDebug2.connectToDB2();

	

	DB2ConnectDebug2.doQuery();

	

	DB2ConnectDebug2.closeUpShop();

	

	DB2ConnectDebug2.deReg();

	



}



/**

 * 

 */

private static void closeUpShop() {

// Trying to close out connection

	try {

		System.out.println ("Closing Db2 connection");

		db2_conn.close();

		System.out.println("IsClosed?="+db2_conn.isClosed());

		

	}catch (SQLException e) {

		System.out.println ("Could not close Db2 connection");

	}

	

}

/**

 * 

 */

private static void doQuery() {

	try {

		String db2query_a="SELECT COUNT(*) FROM DB2ADMIN.PRODUCT_LIST";

		PreparedStatement pstmt_db2= db2_conn.prepareStatement(db2query_a);

		ResultSet r_pl = pstmt_db2.executeQuery();

		r_pl.next();

		String a=r_pl.getString(1);

		System.out.println(a);

		pstmt_db2.close();

		

	}catch(SQLException e){

		System.out.println("FAILED: Fetch statement failed: " + e.getMessage());

		System.out.println(e.getLocalizedMessage());

		e.printStackTrace();

	}

	

}

private static void deReg() {

	try{

		DriverManager.deregisterDriver(drv);

		System.out.println("Successful De-Registering of DB2 Driver");

		DB2ConnectDebug2.listDrivers();

		System.out.println("DB2Driver is loaded?"+DB2Driver.loaded);

		

	}catch(SQLException s){

		System.out.println("Error DE-Registering DB2 Driver");

		DB2ConnectDebug2.listDrivers();

		System.out.println(s.getMessage());

		s.printStackTrace();

}

}

private static void retryReg() {

	try{

		DriverManager.deregisterDriver(drv);

		System.out.println("Successful De-Registering of DB2 Driver");

		try{

		System.out.println("Trying to re-register DB2 Driver");

		drv=(Driver)Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();

		System.out.println("Registered DB2 Driver");}

		catch(Exception e){

			System.out.println("Could not re-register...");

		}

	}catch(SQLException s){

		System.out.println("Error DE-Registering DB2 Driver");

		System.out.println(s.getMessage());

		s.printStackTrace();

	}

}



private static void reg() {

	try {

		drv=new COM.ibm.db2.jdbc.app.DB2Driver();

		p=new Properties();

		p.put("user","user");

		p.put ("password","password");

		

		//Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();

		System.out.println("DB2Driver is loaded?"+DB2Driver.loaded);

		System.out.println("Registered DB2 Driver");

		System.out.println("Buildlevel:"+DB2Driver.buildLevel);

		System.out.println("MajorVersion "+DB2Driver.MajorVersion);

		System.out.println("MinorVersion "+DB2Driver.MinorVersion);

		DB2ConnectDebug2.listDrivers();

	}

	catch (Exception db2err) {

		System.out.println("Error Registering DB2 Driver");

		db2err.printStackTrace();

		//Attempt to deregister

		//DB2ConnectDebug.deReg();



		}

}



/**

 * 

 */

private static void listDrivers() {

	// TODO Auto-generated method stub

	Enumeration en=DriverManager.getDrivers();

	while (en.hasMoreElements()){

		Driver d=(Driver)en.nextElement();

	System.out.println("DriverClass*** "+d.getClass().getName());}

}

private static void connectToDB2 (){

	try{

		//db2_conn= DriverManager.getConnection(devdb2url,username,password);

		db2_conn=drv.connect(devdb2url,p);

		System.out.println("Connected to DB2");

		//System.out.println(DriverManager.getDrivers());

		

		

	}catch (SQLException e){

		System.out.println("STACK:" );

		e.printStackTrace();

		System.out.println("Error Code:"+e.getErrorCode());

		System.out.println("Error Message: "+e.getMessage());

		System.out.println("Cause: "+e.getCause());

		System.out.println("Localized Message"+e.getLocalizedMessage());

		System.out.println("SQLState: "+e.getSQLState());

		System.out.println("Attempting to re-use existing DB2 connection");

		//DriverManager.deregisterDriver(())

		System.out.println(DriverManager.getDrivers());

	}

}

}

Thanks

Subject: Does anyone have an agent that accesses DB2 that works?

My one recommendation is to make sure the credentials that your Domino Server runs on is allowed to access the DB2 client setup. The domino agent settings are not the proper area to be looking at in this case.

Subject: Does anyone have an agent that accesses DB2 that works?

Torstan -

We have Java agents that hit DB2 without incident. Just out of curiosity, do you have the DB2 driver’s jar file attached to the design note of the agent? The security problems may be from restrictions in the java.policy file (vs. the agent itself).

dgg

Subject: RE: Does anyone have an agent that accesses DB2 that works?

Dallas you are right on the money.

I dumped using the .app.DB2Driver driver and went for the type 4 driver about about 4am. jcc.Db2Driver

Runs fine on the client, kicks a SecurityManager error on the server despite full access.

So removed the jcc jars from the design note and put the 2 jcc jar files in the jvm\lib\ext where they have All Permissions, and the security error has dissapeared.

So now i have a working agent that can repeat without giving a driver error.

Question now is: can it be done with the jcc jars in the Agent design note ? How does one set their permissions ?

Subject: RE: Does anyone have an agent that accesses DB2 that works?

As far as security goes, I think it could be done. You’d just have to work through it based on the details of the stack trace and modify the permissions as required. But in my opinion, for something you’ll be using over and over again (like a JDBC driver) you’re better off to have the jar file on the file system vs. in the design note. And I haven’t had good luck attaching jar files to design notes anyway . . . see ->.dgg

Subject: SolvedDoes anyone have an agent that accesses DB2 that works?

Dallas thanks for your help.

Short answer is: dont use the .app.DB2Driver

Use the jcc.DB2Driver

And place a copy of the db2jcc.jar and db2jcc_license_cu.jar in your Domino or Notes jvm\lib\ext folder. (Dion’t Store them in the Agent Design Note - ie: don’t import the jars into the Agent.)

Lastly be aware of the java.policy file and back it up before you make changes to it.