cancel
Showing results for 
Search instead for 
Did you mean: 

Why could Activiti Test class not getting mysql database access

pratikbhatt
Champ in-the-making
Champ in-the-making
package org.pratik;

import java.util.List;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.task.Task;

public class ProcessTestFormService {

   public static void main(String[] args) {

      // Create Activiti process engine
      ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration()
            .buildProcessEngine();

      // Get Activiti services
      RepositoryService repositoryService = processEngine
            .getRepositoryService();
      RuntimeService runtimeService = processEngine.getRuntimeService();

      // Deploy the process definition
      repositoryService.createDeployment()
            .addClasspathResource("FinancialReportProcess.bpmn20.xml")
            .deploy();

      // Start a process instance
      String procId = runtimeService.startProcessInstanceByKey(
            "financialReport").getId();

      // Get the first task
      TaskService taskService = processEngine.getTaskService();
      List<Task> tasks = taskService.createTaskQuery()
            .taskCandidateGroup("accountancy").list();
      for (Task task : tasks) {
         System.out
               .println("Following task is available for accountancy group: "
                     + task.getName());

         // claim it
         taskService.claim(task.getId(), "fozzie");
      }

      // Verify Fozzie can now retrieve the task
      tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
      for (Task task : tasks) {
         System.out.println("Task for fozzie: " + task.getName());

         // Complete the task
         taskService.complete(task.getId());
      }

      System.out.println("Number of tasks for fozzie: "
            + taskService.createTaskQuery().taskAssignee("fozzie").count());

      // Retrieve and claim the second task
      tasks = taskService.createTaskQuery().taskCandidateGroup("management")
            .list();
      for (Task task : tasks) {
         System.out
               .println("Following task is available for accountancy group: "
                     + task.getName());
         taskService.claim(task.getId(), "kermit");
      }

      // Completing the second task ends the process
      for (Task task : tasks) {
         taskService.complete(task.getId());
      }

      // verify that the process is actually finished
      HistoryService historyService = processEngine.getHistoryService();
      HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery().processInstanceId(procId)
            .singleResult();
      System.out.println("Process instance end time: "
            + historicProcessInstance.getEndTime());
   }

}

<strong>I am getting this exception when I am accessing class above</strong>

java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:196)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:180)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:176)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:80)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:371)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:80)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:525)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:487)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:332)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:310)
   at org.pratik.ProcessTestFormService.main(ProcessTestFormService.java:20)
Jul 05, 2013 4:29:28 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectDbSchemaVersion
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:54)
   at org.activiti.engine.impl.db.DbSqlSession.getDbVersion(DbSqlSession.java:740)
   at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:696)
   at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1097)
   at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
   at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:75)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:311)
   at org.pratik.ProcessTestFormService.main(ProcessTestFormService.java:20)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at java.sql.DriverManager.getConnection(DriverManager.java:604)
   at java.sql.DriverManager.getConnection(DriverManager.java:190)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:181)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:176)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:80)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:371)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:80)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:131)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:58)
   at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)
   at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69)
   at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
   at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
   at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)
   at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
   at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
   … 13 more

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectDbSchemaVersion
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:54)
   at org.activiti.engine.impl.db.DbSqlSession.getDbVersion(DbSqlSession.java:740)
   at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:696)
   at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1097)
   at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
   at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:75)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:311)
   at org.pratik.ProcessTestFormService.main(ProcessTestFormService.java:20)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
   at java.sql.DriverManager.getConnection(DriverManager.java:604)
   at java.sql.DriverManager.getConnection(DriverManager.java:190)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:181)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:176)
   at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:80)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:371)
   at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:80)
8 REPLIES 8

jbarrez
Star Contributor
Star Contributor
It tries to go to an H2 db, not a Mysql db:

> No suitable driver found for jdbc:h2:tcp://localhost/activiti

pratikbhatt
Champ in-the-making
Champ in-the-making
Thank you sir for reply, but I have configured activiti.config.xml for mysql yet this error occurring on and on… please give me the guideline if I am missing something
Here is the activiti.config.xml file below.

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
  <property name="jdbcUrl" value="jdbc.mysql://localhost:3306/Activiti" />
  <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
  <property name="jdbcUsername" value="root" />
  <property name="jdbcPassword" value="root" />
  <property name="databaseSchemaUpdate" value="true"/>
</bean>

frederikherema1
Star Contributor
Star Contributor
How do you bootstrap you're process-engine? It seems that the activiti.cfg.xml is not used…

monika_b
Champ in-the-making
Champ in-the-making
.

monika_b
Champ in-the-making
Champ in-the-making
Able to resolve it. I just removed spring style of configuration and used simple way as per user guide. pasting same might help someone.

My activiti.cfg file is:
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
 
    <property name="jdbcUrl" value="jdbcSmiley Surprisedracle:thin:@(DESCRIPTION =(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = <your IP Address>)(PORT = <your port no>)))(CONNECT_DATA =(SERVER = DEDICATED)(SID =<your SID>)))" /" />
    <property name="jdbcDriver" value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUsername" value="<your username>" />
    <property name="jdbcPassword" value="<your password>" />
   
    <property name="databaseSchemaUpdate" value="true" />
   
    <property name="jobExecutorActivate" value="false" />
   
    <property name="mailServerHost" value="mail.my-corp.com" />
    <property name="mailServerPort" value="5025" />   
  </bean>

</beans>

and

main method is:
public class MainApp {
/**
  * @param args
  */
public static void main(String[] args) {
                ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); 
  RepositoryService repositoryService = processEngine.getRepositoryService();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  repositoryService.createDeployment().addClasspathResource("diagrams/MyProcess.bpmn20.xml").deploy(); 
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
  System.out.println("Started Process instance id " +processInstance.getProcessInstanceId());
}

monika_b
Champ in-the-making
Champ in-the-making
I am facing the same issue. I am bootstrapping through below main method. Please help I am very new to activiti.

Exception:  java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver

michael_vu
Champ in-the-making
Champ in-the-making
Hi,
I can resolve this problem by add db.properties file, and set jdbc.url to my Activiti database
jdbc.url=jdbcSmiley Tongueostgresql://localhost:5432/activiti

frederikherema1
Star Contributor
Star Contributor
Thanks for coming back on this. You should indeed make sure you use the "activiti.cfg.xml" as name, if you use createStandaloneProcessEngineConfiguration(). if you're config file has a different name or is located elsewhere, you can always use createProcessEngineConfigurationFromInputStream(..).