how to connect and write on db using groovy connector
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:@18.104.22.168: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
Did you try to execute your process and see if it would work, instead of evaluating it only?
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;
- * 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
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.
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.
Hello, Try maybe
import groovy.sql.Sql; // don't forget the ;
// then define your variable Sql sql = Sql.newInstance("jdbc:oracle:thin:@22.214.171.124:1583:DNLCLONE", "apps", "spider123", "oracle.jdbc.pool.OracleDataSource");
Else create a connector in Java.
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