AnsweredAssumed Answered

My Java jdbc class couldn't be accessed through Activity

Question asked by pratikbhatt on May 16, 2013
Latest reply on May 19, 2013 by ronald.van.kuijk
<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>

Outcomes