JDBC and update with variable number of fields

A

Alessandro

Thinking about making dynalic a JDBC update according to number of fields to
be updated. In my case we have an update to be executed cyclically and at
every cycle I receive values to be updated from another source and they can
be different each time.

This is the classical base for update:
PreparedStatement ps = conn.prepareStatement("UPDATE Messages SET
description = ?, author = ? WHERE id = ? AND seq_num = ?");
ps.setString(1,description);
ps.setString(2,author);
ps.setInt(3,id);
ps.setInt(4,seqNum);
Any idea ? Hibernate simplifies a lot but it needs - look at precedent
post - a preliminary select for each update.Thanks and best
regards,Alessandro
 
M

Manish Pandit

Thinking about making dynalic a JDBC update according to number of fields to
be updated. In my case we have an update to be executed cyclically and at
every cycle I receive values to be updated from another source and they can
be different each time.

This is the classical base for update:
PreparedStatement ps = conn.prepareStatement("UPDATE Messages SET
description = ?, author = ? WHERE id = ? AND seq_num = ?");
    ps.setString(1,description);
    ps.setString(2,author);
    ps.setInt(3,id);
    ps.setInt(4,seqNum);
Any idea ? Hibernate simplifies a lot but it needs - look at precedent
post - a preliminary select for each update.Thanks and best
regards,Alessandro

How are you getting the sequence number? If you're running 1 VM then
have Java code generate the sequence number. If you're using MySQL,
use the autonumber field if that helps..

-cheers,
Manish
 
R

Roedy Green

Thinking about making dynalic a JDBC update according to number of fields to
be updated. In my case we have an update to be executed cyclically and at
every cycle I receive values to be updated from another source and they can
be different each time.

This is the classical base for update:
PreparedStatement ps = conn.prepareStatement("UPDATE Messages SET
description = ?, author = ? WHERE id = ? AND seq_num = ?");
ps.setString(1,description);
ps.setString(2,author);
ps.setInt(3,id);
ps.setInt(4,seqNum);
Any idea ? Hibernate simplifies a lot but it needs - look at precedent
post - a preliminary select for each update.Thanks and best
regards,Alessandro
You could have an array of PreparedStatements and select the
appropriate one.

This seems a bit odd. I think of SQL records having a fixed field
structure. Perhaps you could feed SQL an array field (a common
extension), or a blob of some sort to deal the variable portion.


--
Roedy Green Canadian Mind Products
http://mindprod.com

"We must be very careful when we give advice to younger people: sometimes
they follow it!"
~ Edsger Wybe Dijkstra, born: 1930-05-11 died: 2002-08-06 at age: 72
 
A

Arne Vajhøj

Roedy said:
You could have an array of PreparedStatements and select the
appropriate one.

This seems a bit odd. I think of SQL records having a fixed field
structure. Perhaps you could feed SQL an array field (a common
extension), or a blob of some sort to deal the variable portion.

The fact that a record has a fixed number of fields does not
imply that an update has to update a fixed number of fields.

Arne
 
R

Roedy Green

The fact that a record has a fixed number of fields does not
imply that an update has to update a fixed number of fields.

Thunk thunk, (sound of head hitting desk).
--
Roedy Green Canadian Mind Products
http://mindprod.com

"We must be very careful when we give advice to younger people: sometimes
they follow it!"
~ Edsger Wybe Dijkstra, born: 1930-05-11 died: 2002-08-06 at age: 72
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top