incubator-empire-db-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <doeb...@esteam.de>
Subject re: Why the connection is given two times in case of UPDATE?
Date Mon, 16 Aug 2010 07:07:56 GMT
This is how to do it:

 

// Update a record using a DBCommand object

DBCommand cmd = db.createCommand();

cmd.set(db.EMPLOYEES.SALARY.to(50000));

cmd.where(db.EMPLOYEES.EMPLOYEE_ID.is(123));

db.executeSQL(cmd.getUpdate(), conn);

 

Regards

Rainer

 

from: exxos [mailto:hatufr@gmail.com] 
to: empire-db-user@incubator.apache.org
re: Re: Why the connection is given two times in case of UPDATE?

 

Hi Rainer,

Thank you for your reply.

Could you please just give a short example on how to perform an UPDATE with a DBCommand?

Regards,
exxos.



On Sun, Aug 15, 2010 at 11:04 PM, Rainer Döbele <doebele@esteam.de> wrote:

Hi exxos,

 

In your update example the call to rec.read() will read the record from the database by executing
a corresponding SELECT statement.

The UPDATE then only updates the changed fields.

 

It is part of our design, that we don't store connections since they are an external resource
that might be shared between threads or requests and hence a connection must be supplied every
time a database action is performed. But you may add your own layer (e.g. by deriving a class
from DBRecord) to implement a connection handling that suits your purpose.

 

If you don't want to read before an update - e.g. if you know that the value will change and
don't need the extra logic - then you should use a DBCommand to update a record. 

 

Regards,

Rainer

 

 

from: exxos [mailto:hatufr@gmail.com] 
to: empire-db-user@incubator.apache.org
re: Why the connection is given two times in case of UPDATE?

 

Hello,

 

Sorry to spam the august's mailling list. ^__^

 

But, I need a clarification on the implementation for the INSERT and the UPDATE methods.

 

Accroding you tutorial, the following steps are needed:

 

// INSERT
DBRecord rec = new DBRecord();
rec.create(DBRowSet table);
rec.setValue(...)
rec.update(java.sql.Connection conn);

 

// UPDATE
DBRecord rec = new DBRecord();
rec.read(..., java.sql.Connection conn);
rec.setValue(...)
rec.update(java.sql.Connection conn);


Why in case of the UPDATE we have to give the Connection by two times?

 

Thank to advise,

Regards.

 

 

 


Mime
View raw message