| Author |
Clone a record in the database or element in an arrayList
|
Reggie McDougal
Ranch Hand
Joined: Sep 27, 2004
Posts: 69
|
|
I have a result set saved into an ArrayList, how would I go about cloning a record or element in the arrayList. Then if I add an new record I have to insert in instead of updating in the database. How might bI appraoch this problem. Reg
|
You can never drink too much
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
Reggie, You have an ArrayList or what? Different resultsets? References to something? If you had DTO (data transfer objects), it would make sense to clone the object. If they are really database objects, you have to make the copy yourslef and change the fields before adding it. An O/R framework would also be useful in abstracting the database code.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Reggie McDougal
Ranch Hand
Joined: Sep 27, 2004
Posts: 69
|
|
Ok lets just say I want to clone a row in a table, how maight I do that? Reg
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
Reg, Using pure JDBC: 1) Read row from table into data structure 2) Create new row with that data (and different primary key) As I said earlier, I think you would benefit from using an O/R framework. You are already thinking at a higher level of abstraction (thinking about cloning rather than copying rows) so it may be easier to work with objects.
|
 |
Avi Abrami
Ranch Hand
Joined: Oct 11, 2000
Posts: 1112
|
|
Reggie,
I want to clone a row in a table
Do you mean that you want to insert the same row, a second time? In other words, you want the same row to appear twice in the same table? You are aware, I assume, that you won't be able to do this if there is a unique index (or primary key) defined for the particular table, aren't you? Or do you want to copy a row from one table to another? In either case, you can do this via SQL alone. Most databases support something like: So no need for data structures in java. (Or am I missing something?) Good Luck, Avi.
|
 |
 |
|
|
subject: Clone a record in the database or element in an arrayList
|
|
|