• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to move data to other table

 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm still a novice to jdbc, i want to know how to move rows of data from a table to another table.
Is it as simple as select all data from table A then grab the resultSet and insert them to table B ?
Can anyone give any example please?
Any feedbacks will be fully appreciated


Rgds,

paula
 
Satish SN
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i am not clear with ur problem bcoz moving all rows from table to another is not dependent on the JDBC but the database.

u did not mention both these table are identical i mean have the same columns or different
if have the same number of columns then u can simply execute the following sql command through JDBC

assume tabA, tabB u want to move tabA rows to tabB

insert into tabB select * from tabA (where condition if applies)
 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot
Btw i have another question, can i parse timestamp value i retrieved using ResultSet to int value?
I have to move tabA rows to tabB rows which dates are 7 days before the current date.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pingkan paula:
I have to move tabA rows to tabB rows which dates are 7 days before the current date


Why don't you add a where clause in your table like

select col1,col2,col3 from myTable where MyDateColumn <= sysdate -7

This is Oracle specific query , look at your DB manuals for details.

Shailesh
 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx, i'm using two connection to select and insert the data, However i got this error:
database errorjava.sql.SQLException: Duplicate entry '628151308255020050901000153496-nRn2Rkp4c01' for key

I have used SELECT DISTINCT to avoid redundancy, but it still doesn't work


However, this is the snippets
 
Eric Gero
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duplicate entry '628151308255020050901000153496-nRn2Rkp4c01' for key

Looks like you are trying to write a key that already exists in the second table. Maybe you could you try using IF NOT EXISTS(Select colName from table) before your insert statement to make sure the value you are writing is unique.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic