cancel
Showing results for 
Search instead for 
Did you mean: 

My Java jdbc class couldn't be accessed through Activity

pratikbhatt
Champ in-the-making
Champ in-the-making
<strong>For Database Connectivity I have Created class as below</strong>

package com.db.connection;

import java.sql.*;

public class DbConnection {
   
   private String JDBC_DRIVER = "com.mysql.jdbc.Driver";
   private String JDBC_URL = "jdbc:mysql://localhost:3306/Pratik";
   public Connection cnn;
   
   public Connection connection(){
      try {
         Class.forName(JDBC_DRIVER);
         cnn = DriverManager.getConnection(JDBC_URL,"root","root");
      } catch (ClassNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (Exception e){
         e.printStackTrace();
      }
      return cnn;
   }

}


<strong>for accessing "Activiti form data" in java class I have created class as below</strong>
package com.db.connection;

import java.sql.*;
import org.activiti.engine.delegate.*;
import com.bean.*;

public class InsertQuery implements JavaDelegate{
   
   public Connection cnn;
   public Statement stmt;
   public String sql, name;
   public boolean status;
   public long ai;
   
   public void query(String name, long ai, boolean status){
      DbConnection dc = new DbConnection();
      try {
         sql = "insert into loan values('" + name + "'," + ai + ",'" + String.valueOf(status) + "');";
         cnn = dc.connection();
         stmt = cnn.createStatement();
         stmt.executeUpdate(sql);
         System.out.println("Record Successfully Inserted");
      } catch (SQLException e) {
         e.printStackTrace();
      }
   }
   @Override
   public void execute(DelegateExecution exec){
      try{
         CustomerDetails cd = new CustomerDetails();
         
         cd.setName((String)exec.getVariable("name"));
         cd.setAi((Long)exec.getVariable("ai"));
         cd.setStatus((Boolean)exec.getVariable("status"));
         cd.setEmail((String)exec.getVariable("email"));
         exec.setVariable("loanApplication", cd);
         
         name = (String)exec.getVariable("name");
         ai = (Long)exec.getVariable("ai");
         status = (Boolean)exec.getVariable("status");
         
         InsertQuery iq= new InsertQuery();
         iq.query(this.name, this.ai, this.status);
         
      } catch (Exception e){
         System.out.println(e);
      }
   }
}

<Strong>package com.bean;</Strong>

import java.io.*;

public class CustomerDetails implements Serializable{
   
   private static final long serialVersionUID = 1L;
   String name;
   long ai;
   boolean status;
   String email;
   
   public String getName(){
      return name;
   }
   
   public void setName(String name){
      this.name = name;
   }
   
   public long getAi() {
      return ai;
   }

   public void setAi(long ai) {
      this.ai = ai;
   }

   public boolean getStatus(){
      return status;
   }
   
   public void setStatus(boolean status){
      this.status = status;
   }
   
   public String getEmail(){
      return email;
   }
   
   public void setEmail(String email){
      this.email=email;
   }
}


<strong>My problem is that whenever I start process from activiti explorer, all process could be completed successfully but record insertion to database couldn't be done and also variable couldn't be settled…
Please help me on this issue if any solution there</strong>
5 REPLIES 5

pratikbhatt
Champ in-the-making
Champ in-the-making
<Strong>This file is for Activiti BPM Process</Strong>

sebastian_s
Champ in-the-making
Champ in-the-making
Hello Pratik,

you didn't give a sufficient description of your problem and you did not provide an exception stacktrace either.

Sebastian

pratikbhatt
Champ in-the-making
Champ in-the-making
Hello Sebastian
Actually no error arise in this code, but somehow data from filled form can't be inserted using above jdbc connection… and I have tested above jdbc code in separate simple java class to insert data in database, and this code work fine but when I am trying to insert data from Activiti Process Form, No data can be inserted through this class. all necessary .jar files are included where those files are needed.
Thank you

pratikbhatt
Champ in-the-making
Champ in-the-making
Hello Sebastian

When I am doing unit testing I can find these warnings on Eclipse console


May 18, 2013 11:37:18 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [activiti.cfg.xml]
May 18, 2013 11:37:20 AM org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
INFO: performing create on engine with resource org/activiti/db/create/activiti.h2.create.engine.sql
May 18, 2013 11:37:20 AM org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
INFO: performing create on history with resource org/activiti/db/create/activiti.h2.create.history.sql
May 18, 2013 11:37:20 AM org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
INFO: performing create on identity with resource org/activiti/db/create/activiti.h2.create.identity.sql
May 18, 2013 11:37:20 AM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine default created
May 18, 2013 11:37:20 AM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource sales.bpmn20.xml
May 18, 2013 11:37:20 AM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
May 18, 2013 11:37:20 AM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
id 5 sales:1:4

please help me to solve my problem

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
What you post now are no warnings, but INFO messages… And if you don't have more info, it is impossible for us to help.

And if System.out.println("Record Successfully Inserted"); is called but there is no data…. i'd check transaction management or (auto)commit