java.lang.ClassNotFoundException

I am trying to write a Java agent that will do a query in a db2 table and bring back the results. We added the JavaUserClasses=/QIBM/ProdData/http/public/jt400/lib/jt400.jar

to the Notes.ini file

I am using the below code in an agent but i get the following error:

java.lang.ClassNotFoundException

at java.lang.Class.forName1(Native Method)

at java.lang.Class.forName(Class.java:142)

at JavaAgent.NotesMain(JavaAgent.java:27)

at lotus.domino.AgentBase.runNotes(Unknown Source)

at lotus.domino.NotesThread.run(NotesThread.java:215)

Can someone PLEASE tell me what I am doing wrong!?!?!?!?

import lotus.domino.*;

import java.sql.*;

import java.util.Vector;

import java.io.PrintWriter;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

String url = "jdbc:as400://ip address/TSTTELDTA";

//String url = "jdbc:db2:ip address/TSTTELDTA";

 String username = "login";

 String password = "password";

 

try {

Session session = getSession();

AgentContext agentContext = session.getAgentContext();

 PrintWriter pw = getAgentOutput();

 Database db = agentContext.getCurrentDatabase();

 Vector agents = db.getAgents();

  Document doc = agentContext.getDocumentContext( );

      

 pw.println("Got Here - - Just before Driver = 1"); 

 pw.println(" ");        

 Class.forName("/QIBM/ProdData/http/public/jt400/lib/jt400.jar");

 pw.println("Got Here - - After the Driver = 2");

 pw.println(" ");     

 

 Connection conn = DriverManager.getConnection( url,username, password );     

 Statement statement = conn.createStatement();

 ResultSet rs = statement.executeQuery("Select MMSNO,HDESC FROM TSTTELDTA.CALHST WHERE HMMSNO = 00967969" );

		

 pw.println("Got Here - - After the conection and Select Statements = 3");



while( rs.next() )

// Create a document and populate the fields

			doc = db.createDocument();

			doc.replaceItemValue("Form", "Customer");

			doc.replaceItemValue("Name", rs.getString("MMSNO"));

			doc.replaceItemValue("Address", rs.getString("HDESC"));

			doc.save(true, true);

			pw.println("Got Here - - Created the doc = 4");

              System.out.println();

               statement.close();

              conn.close();

}

catch(Exception e) {

 e.printStackTrace();

  }

}

}

Subject: java.lang.ClassNotFoundException

Michael,

I’m guessing you are getting this error when you try to save your agent and not later when you go to run it. If so, add the jt400.jar file to the project. Click on “Edit Project” at the bottom in Designer and navigate to the jt400.jar file and add it.

Ken

Subject: RE: java.lang.ClassNotFoundException

Upon compile I get no errors, I get this when i run the agent. I will try your suggestion non the less

Subject: java.lang.ClassNotFoundException

Hello!

This line ist not correct

Class.forName(“/QIBM/ProdData/http/public/jt400/lib/jt400.jar”);

replace is it with this

Class.forName(“com.ibm.as400.access.AS400JDBCDriver”);

The parameter is not a file in the file system. it is a java class.

Maybe there are other problems in your code, but this solution for the posted error message.

Greetings from Austria

Ralf M Petter

Subject: RE: java.lang.ClassNotFoundException

I did what you said and I get the following error:

java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver

at lotus.domino.AgentLoader.loadClass(Unknown Source)



at java.lang.ClassLoader.loadClass(ClassLoader.java:448)



at java.lang.Class.forName1(Native Method)



at java.lang.Class.forName(Class.java:142)



at JavaAgent.NotesMain(JavaAgent.java:29)



at lotus.domino.AgentBase.runNotes(Unknown Source)



at lotus.domino.NotesThread.run(NotesThread.java:215)

Subject: RE: java.lang.ClassNotFoundException

Michael,

I can’t speak for AS/400 but does that jar file you mention contain com.ibm.as400.access.AS400JDBCDriver?

I found that I could not get JDBC to work until I made the method that contains the “Class.forName” statement – static.

Do a search on my postings containting JDBC and you might find a tip or two that will help.

Ken

Subject: RE: java.lang.ClassNotFoundException

I have tried it in the below 3 different waysfor some reason the agent will not find it

I get “class not found”

mmarcavage@andersontechs.com

DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());

Class.forName(“/QIBM/ProdData/http/public/jt400/lib/jt400.zip”);

Class.forName(“com.ibm.as400.access.AS400JDBCDriver”);

Subject: RE: java.lang.ClassNotFoundException

Michael,

You should not be going back to those old ways of referencing the JAR file. Ralf told you what you need. “Class not found” can also mean “I don’t have authority to access the class”. So make sure your agent has the authority. It could be an OS setting. I suggested you read my old posts – one of the tips I mentioned is setting the agent properties security to 3 which gives your agent certain rights involving accessing files outside the Notes world which reside on the hard drive.

Ken

Subject: RE: java.lang.ClassNotFoundException

I will try this.

I am sure that the rest of the code has errors and I will fix them once I get past the connection problem.

Do you know of any good resources for Java and Notes. I am not able to find my help on this.

Subject: RE: java.lang.ClassNotFoundException

Michael,

 Unfortunately, I have not found any Notes and Java documentation.  It stinks being the "bleeding edge" because every time I post a question to this forum about Java and Notes, I never get a response since not many people are doing this.  

Ken

Subject: RE: java.lang.ClassNotFoundException

can you give me the steps on how to make this work? No matter what I do I am not able to get this to work. I am not able to find anything on this.

If we may, please send to my e-mail address so that I can get this to move a little quicker

mmarcavage@andersontechs.com

Subject: RE: java.lang.ClassNotFoundException

Ok there is much java documentation on the net. Just google for it. And the Notes classes are pretty well documented in the Designer help. So where is the problem. Anyway the problem in this thread is not a notes java problem. It is a pure JDBC JT400 question.

Greetings from Austria

Ralf M Petter

Subject: RE: java.lang.ClassNotFoundException

can you give me the steps on how to make this work? No matter what I do I am not able to get this to work. I am not able to find anything on this.

If we may, please send to my e-mail address so that I can get this to move a little quicker

mmarcavage@andersontechs.com

Subject: java.lang.ClassNotFoundException

Mike:

QNOTES has to have access to any file on the iSeries that you are working with, including JARS. Without it, it is as if they don’t exist.

Have a look at this thread:

http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/5d356fe05382b42f85256c2f00550d37?OpenDocument

And download this demo:

http://www-1.ibm.com/servers/eserver/iseries/domino/devtools/java/javademo.htm

Email me if you are still having problems.

Best of Luck,

–Mac

Subject: RE: java.lang.ClassNotFoundException

I finially got this to work and it works perfectly. Thanks to all that helped me