1 Reply Latest reply on Jul 19, 2013 9:16 AM by jsvitak

    Trying to connect to database through jBPM script task.

    avatarkim

      Hi,

       

      I'm trying to access MySql database through jBPM workflow's script task but I'm getting the error code below when the workflow run the script task. I already uploaded the MySQL driver jar file as POJO in the Guvnor and I'm still getting this error.
      "No suitable driver found for jdbc:mysql://localhost:3306/test"

      so I'm assuming the jBPM need some other way for it to handle MySQL driver jar but I don't know where and what should I do this for this to work.

       

      Below is my code in my Workflow's Script Task

       

      java.sql.Connection con = null;

      java.sql.PreparedStatement pst = null;

      java.sql.ResultSet rs = null;

      java.sql.ResultSetMetaData rsmd = null;

       

       

      String url = "jdbc:mysql://localhost:3306/test";

      String user = "root";

      String password = "password";

       

       

      String temp = "DEBUG: ";

       

       

      try

      {

          con = java.sql.DriverManager.getConnection(url, user, password);

          pst = con.prepareStatement("SELECT * FROM aquitimber_messages");

          rs = pst.executeQuery();

          rsmd = rs.getMetaData();

       

       

          int rowSize = 0;

          rs.last();

          rowSize = rs.getRow();

          rs.first();

       

       

          for (int countRow = 0; countRow < rowSize; countRow++)

          {

                    for (int count = 1; count < rsmd.getColumnCount(); count++)

              {

                                    System.out.print(rs.getString(count) + ", ");

                                    temp = temp + rs.getString(count) + ", ";

              }

              System.out.println();

              rs.next();

          }

      } catch (java.sql.SQLException ex)

      {

                System.out.println(ex.getMessage());

                temp = temp +ex.getMessage();

      } finally

      {

                try

                {

                          if (rs != null)

                          {

                                    rs.close();

                          }

                          if (pst != null)

                          {

                                    pst.close();

                          }

                          if (con != null)

                          {

                                    con.close();

                          }

                } catch (java.sql.SQLException ex)

                {

                          System.out.println(ex.getMessage());

                          temp = temp +ex.getMessage();

                }

      }

       

       

      kcontext.setVariable("approvalVar_history", temp);

       

      Any help on this would be greatly appreciated. Thank you.

        • 1. Re: Trying to connect to database through jBPM script task.
          jsvitak

          Hi avatarkim,

           

          what version of jBPM do you use?

           

          You should not use script tasks for interaction with a database. Use rather a service task and implement own handler. Script tasks are very simple, so service tasks can save you from many headaches with db interaction.

           

          Regarding to your issues with MySQL driver - you should not upload the MySQL driver into Guvnor, only POJOs. What are you trying to achieve? If you are using JBoss AS/Wildfly, you should load MySQL driver as a module or a deployment. Do not include it in your application, or even upload into Guvnor. Also remember that Guvnor is only a repository, so I expect that you wanted to use jbpm console or own web application to run the process instances.

           

          HTH