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