how to connect and write on db using groovy connector

1
0
-1

i create one connector (groovy)

and use following code

import groovy.sql.Sql; import java.sql.Driver;

import groovy.sql.Sql sql = Sql.newInstance("jdbc:oracle:thin:@200.200.1.224:1583:DNLCLONE", "apps", "spider123", "oracle.jdbc.pool.OracleDataSource") sql.execute( """INSERT INTO XX_HOTEL (NAME,ADDRESS) VALUES(?, ?)""", [test,test])

when i eveluate it ask for test variable value it is ok , but ask for sql value why ? and sql statement give following alert error with yellow triangle sign "sql cannot be resolved. It may lead to runtime errors."

how can i solve it pl provide perticular script for wirte on external db

Comments

Submitted by haris.subasic on Tue, 04/01/2014 - 15:27

Did you try to execute your process and see if it would work, instead of evaluating it only?

Submitted by kppatel on Wed, 04/02/2014 - 06:50

sir thanks for reply ,

ya i tried to execute process , but it now successfully work it failed at connector execution stage .

any alternative pl let i know thanks kandarp

3 answers

1
0
-1

HI,

In order to execute SQL query inside a groovy script, you have to use a dedicated wrapper provided by Bonita BPM.

BonitaSql sql = BonitaSql.newInstance(url,user,password,driver);

You can find the documentation and a shortcut to this Object in the right panel in "Bonita" category.

Note that this object currently support only single connection. For your use case, I think you have to adapt the code of this object in order to access to your connection pool.

Here is the code of BonitaSql

import java.sql.Driver;
import groovy.sql.Sql;

public class BonitaSql {

        /**
         * Creates a new Sql instance given a JDBC connection URL.
         * @param url a database url of the form jdbc:subprotocol:subname
         * @param user
         * @param password
         * @param driver an instance of the java.sql.Driver to use
         * @return  a new Sql instance with a connection
         */

        public static Sql newInstance(String url,String user,String password,Driver driver){

                Properties p= new Properties()
                p.setProperty("user",user)
                p.setProperty("password",password)
                return new Sql(driver.connect(url, p))

        }
}

Note that I advice you to minimize the use of groovy script for your project. Groovy is really usefull to prototype within Bonita BPM but in order to have good performance in production, you should convert your groovy scripts into custom connectors.

1
0
-1

hello, Go to the menu "developement", then "connector" and "new definition". Write the definition of your connector (input, and output value) for example, name and address should be a good candidate for input value. Then, go to "developement", then "connector" and "new implementation". Choose the definition you made, and then put your code in the executeBusinessLogiq(). Attention, you are in Java here, not in Groovy.

I found a documentation here : http://documentation.bonitasoft.com/creating-connector

Second idea, use a Sql connector. For example, the Datasource database query is a connector to play a request. Normally, this connector is use to query a database, but it mays work in update ? I don't know.

Hope that's help.

1
0
-1

Hello, Try maybe

import groovy.sql.Sql; // don't forget the ;

// then define your variable Sql sql = Sql.newInstance("jdbc:oracle:thin:@200.200.1.224:1583:DNLCLONE", "apps", "spider123", "oracle.jdbc.pool.OracleDataSource");

Else create a connector in Java.

Comments

Submitted by kppatel on Wed, 04/02/2014 - 06:49

Sir , Thanks for your reply but whenever i try to code using groovy script and use Sql class of it gives only same error "sql cannot be resolved. It may lead to run-time errors." as well as i tried execute process rather then evaluate but still not working

sir , java connector ? you mean to say i should create custom connector ? because there is no available option in exists script connector to write java code if any other option pl let i know

thanks kandarp

Notifications