This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal


Sep 21, 2017, 4:17 AM
15 Posts
topic has been resolvedResolved

Using JDBC in Java

  • Category: Domino Designer
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer
  • Tags: JDBC
  • Replies: 2

Hi All,

 

After banging my head against a brick wall with LSX Connectors and having constant Notes crashes, and huge memory leaks, I'm admitting defeat. I have used JDBC in Java before, but am having an issue. Thought before I bang my head again too hard would write a simple agent to update a single field in one row...

import lotus.domino.*;
import java.sql.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();

          // (Your code goes here)
 
          String qry="";
         
         
          System.out.println("About to try to connect to mysql");
          Class.forName("com.mysql.jdbc.Driver")
          System.out.println("Connected");
          Connection con=null;   
          String URL="jdbc:mysql://xxx.xxxxxxxxx.xxx";
          String un="xxxxx";
          String pw="xxxxxxxxxxxxxxxxxx";
 
          qry="update xx_xxxx.xxxxxxset BusinessUnit = ? WHERE ClaimNo = ? ";
          con=DriverManager.getConnection(URL, un,pw);
          
          PreparedStatement ps=con.prepareStatement(qry);
          ps.setString(1, "Updated Business Unit");
          ps.setString(2, "99999999");
          
          ps.execute();  
          

      } catch(Exception e) {
          e.printStackTrace();
       }
   }
}

 

I am not getting past - Class.forName("com.mysql.jdbc.Driver"). Get the following error

Exception in thread "AgentThread: JavaAgent" java.lang.ExceptionInInitializerError
    at java.lang.J9VMInternals.ensureError(J9VMInternals.java:141)
    at java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:130)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:82)
    at java.lang.Class.forName(Class.java:287)
    at com.mysql.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:105)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:82)
    at java.lang.Class.forName(Class.java:287)
    at JavaAgent.NotesMain(JavaAgent.java:19)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)
Caused by: java.security.AccessControlException: Access denied ("java.lang.RuntimePermission" "setContextClassLoader")
    at java.security.AccessController.throwACE(AccessController.java:157)
    at java.security.AccessController.checkPermissionHelper(AccessController.java:217)
    at java.security.AccessController.checkPermission(AccessController.java:349)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:562)
    at COM.ibm.JEmpower.applet.AppletSecurity.superDotCheckPermission(AppletSecurity.java:1455)
    at COM.ibm.JEmpower.applet.AppletSecurity.checkRuntimePermission(AppletSecurity.java:1317)
    at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1619)
    at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1470)
    at java.lang.Thread.setContextClassLoader(Thread.java:802)
    at com.mysql.jdbc.AbandonedConnectionCleanupThread$1.newThread(AbandonedConnectionCleanupThread.java:50)
    at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:623)
    at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:936)
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1368)
    at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:679)
    at com.mysql.jdbc.AbandonedConnectionCleanupThread.<clinit>(AbandonedConnectionCleanupThread.java:54)
    ... 10 more

 

I have imported the mySQL JDBC JAR into the archive section of the agent. Set security  to 3 on the agent security.  Any suggestions or help would be gratefully appreciated.

 

Thanks again

 

Cameron

 

Sep 21, 2017, 1:27 PM
323 Posts
On the chance this is just a legitimate exception

This should be added in the file [dominoserver-dir]/jvm/lib/security/java.policy:
grant {
permission java.lang.RuntimePermission “setContextClassLoader”;
permission java.lang.reflect.ReflectPermission “suppressAccessChecks”;
};

-- Courtesy Martin Vereecken

Sep 22, 2017, 12:27 AM
15 Posts
Thanks Mike

Finally see some things working.. now getting

 

Error cleaning up agent threads

Exception in thread "Abandoned connection cleanup thread" java.lang.IllegalMonitorStateException

 

..... something else to hunt down...

 

Thanks again

 

Cameron


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal