ron
ron

Reputation: 5279

how to copy derby table

I am using Eclipse, Java and a Derby database. I want to experiment with changing values that rewrite one of the tables in the db. Before starting the change I would like to copy the particular table (not in code) so that I can restore the original data if necessary. Sof ar googling and searching this site hasnt produced an answer. In Eclipse there is an option to export the db but it calls it a connection so I am not usre what would happen.

Upvotes: 1

Views: 4125

Answers (2)

BillRobertson42
BillRobertson42

Reputation: 12883

If you're not sure about how to connect to the database and issue sql statements, you will need to learn about JDBC. This is a good place to start.

If you're asking about the SQL, it's pretty straight forward. You can create a table based on a select statement.

e.g.

create table table2 as select * from table1 with no data;

Derby is a little strange in this area. You must specify the with no data, and the created table will be empty. You can then issue an insert that will populate the new table if you wish.

insert into table2 select * from table1;

The new table will not have indexes. You will need to create them if you want them. It might retain the primary key. You should check that if you're testing against it. If it doesn't retain the primary key, you should create the primary key before inserting data into the table.

Upvotes: 4

MaDa
MaDa

Reputation: 10762

In Eclipse there is an option to export the db but it calls it a connection so I am not sure what would happen.

If what Eclipse does isn't clear for you, you can just as well zip your entire database directory (content of DERBY_HOME env. variable) into an archive. The database must not be running while you make the backup.

Upvotes: 0

Related Questions