cancel
Showing results for 
Search instead for 
Did you mean: 

Use mysql database table

agiledevpro
Champ in-the-making
Champ in-the-making
Hi,

I want to create a process that inserts data into a mysql table that I've created. I wonder if this is possible?
I know that activiti uses a h2 database by default, but I want to use a mysql database instead.

I've created a maven project in eclipse and added the following dependency to my pom.xml:
dependency
         groupId mysql groupId
         artifactId mysql-connector-java artifactId
         version 5.1.13 version
dependency

I've also added databasetype, jdbcUrl, jdbcDriver, jdbcUsername and jdbcPassword to my activiti.cfg.xml file. Is there anything else I need to do?

I just want data to be added at a certain step in my process, would this be possible to do?

I've also created a JUint test and when I run this I get errors:

org.activiti.engine.ActivitiException: couldn't check if tables are already present using metadata:
### Error getting a new connection.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
   at org.activiti.engine.impl.db.DbSqlSession.isTablePresent(DbSqlSession.java:879)
   at org.activiti.engine.impl.db.DbSqlSession.isEngineTablePresent(DbSqlSession.java:834)
   at org.activiti.engine.impl.db.DbSqlSession.dbSchemaUpdate(DbSqlSession.java:767)
   at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1145)

 

Any suggestions?

Thank you!
4 REPLIES 4

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Did you configure mysql connection properly?
can you connect to mysql server?

Regards
Martin

agiledevpro
Champ in-the-making
Champ in-the-making
Hi,

I've followed the following tutorial "http://www.attuneuniversity.com/blog/change-database-from-h2-to-mysql-in-activiti.html"
that explains how to change from a h2 database to a mysql database in Activiti.

I've changed both db.properties "C:\apache-tomcat-7.0.54\webapps\activiti-rest\WEB-INF\classes" and
"C:\apache-tomcat-7.0.54\webapps\activiti-explorer\WEB-INF\classes"

into:

db=activiti
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/activiti
jdbc.username=root
jdbc.password=root

I've also added the mysql-connector jar into the lib folders and added the properties for this driver in my activiti.cfg.xml file.


I can start my sql server from commando prompt if that is what you meant?
I cannot connect to the server through the browser (localhost:3306).


Do I need to write some java code in order for these changes to be applied, or what am I missing?

When I run my code I get an error saying:
"Exception while initializing Database connection"
"java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver"

But I'm not using a h2 database, so it seems like my changes isn't applied since it tries to use the default database. I don't know what I'm missing.

Regards,

agiledevpro
Champ in-the-making
Champ in-the-making
Hi, again

I've added the following code:

ProcessEngine processEngine = ProcessEngineConfiguration
              .createStandaloneInMemProcessEngineConfiguration()
              .setDatabaseType("mysql")
              .setJdbcUrl("jdbc:mysql://192.168.1.73:3306/activiti")
              .setJdbcDriver("com.mysql.jdbc.Driver")
              .setJdbcUsername("activiti")
              .setJdbcPassword("activiti")
              .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)….

And now it no longer tries to connect to the default database (h2), instead tries to connect to jdbc:mysql://192.168.1.73:3306/activiti which I want. But when I run my code I get the following error:

org.activiti.engine.ActivitiException: couldn't check if tables are already present using metadata:
### Error getting a new connection.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


What am I missing?

Thanks,



agiledevpro
Champ in-the-making
Champ in-the-making
Hi!

It works now, I had to download mysql installer aswell, stupid misstake Smiley Tongue

Thank you for your help!