How to insert data with a mysql connector from bdm?

1
0
-1

def rmaVar = new com.company.model.Rma()
def script = ""
script = "Insert into rma_cliente(nome,cognome,email) Values(" + rmaVar.nome + "," + rmaVar.cognome + "," + rmaVar.email + ")"

This is my query but i get null values in the database.

1 answer

1
0
-1

Hi,

I didn't understand clearly what you want to do, but I supose that you are doing it wrong. I mean:

When you are creating the rmaVar, you are instantiating a new object od the Rma class (of your BDM), but this is a new object and it will be stored on the BDM database, that is not there yet. Since you call the properties of the rmaVar object you only have null values because this is normal, rmaVar is a new object and all its properties are null.

You have to use the DAO objects to get values that are already stored on the BDM database, it's something like this:

def rmaVar = rmaDAO.findByPersistenceId(1) //I try to get the very first row on the data base for the Rma objects.
def script = ""
script = "Insert into rma_cliente(nome,cognome,email) Values(" + rmaVar.nome + "," + rmaVar.cognome + "," + rmaVar.email + ")"

Finally I dont understand why you use another database, you should use the BDM to store that data, It doesn't make sense build another database since you have the BDM.

I hope it helps. Bye.

Comments

Submitted by tabayvesjoelle on Wed, 10/19/2016 - 17:21

hello!! i've followed your solution but something wrong!!
my groovy code:
import groovy.sql.Sql;
import java.sql.Driver;
import com.company.model.MysqlDAO;
class GroovySqlExample1{
static void main(String[] args) {
def sql = Sql.newInstance("jdbc:mysql://localhost:3304/donne", "root",
"123456789", "com.mysql.jdbc.Driver");

def baseVar = mysqlDAO.findByPersistenceId(1);

def script = "insert into test (nom, prenom, age) values ("+baseVar.nom+", "+baseVar.prenom+", "+baseVar.age+")";

sql.execute(script);
}

}

Submitted by dbravo on Wed, 10/19/2016 - 23:11

Hi,

Well, first tell us more about your BDM definition, because you are using first a "Rma" Object, and now you are using a "Mysql" object.

Now, please tell us where are you running this script, is it from an operation?, groovy script connector?, standalone script via Engine API?, etc.

Finally please show us your engine log.

By the way, you have not explained why are you using MySQL queries since the BDM has almost all you need to manage the business data.

Bye.

Submitted by Sean McP on Thu, 10/20/2016 - 23:36

Dear All,

A Tip on displaying CODE/LOGS correctly in Posts:

Do not use the Supplied Buttons above, for some reason they refuse to work correctly, and despite bringing it to Bonitasofts attention, it's low priority.

To Show Code/Logs correctly use

< code >
your code/log
< /code >

removing the spaces to allow the showing of code/logs correctly as here:

your code/log

Thanks and regards
Seán

Notifications