This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Save a table with another name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Save a table with another name?" Watch "Save a table with another name?" New topic
Author

Save a table with another name?

Franco Lucci
Greenhorn

Joined: May 07, 2005
Posts: 6
Hi, I'd like to do a copy of a table in my DB.mdb with another name
but my problem is to do it with java's code.
Ex: I have the CUSTOMERS table in my personal.mdb and I want create a copy of CUSTOMERS with name CUSTOMERS_2005.
Is it possible?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Franco,
Welcome to JavaRanch!

Yes, you can do this through JDBC. You need to create a new table with the same schema. If you have the schema, you can use it. If not, you can use the metadata to get it. Then you insert all the records into the new table and delete the old table.

If you want more details about any of these steps, post here.


[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
Franco Lucci
Greenhorn

Joined: May 07, 2005
Posts: 6
but I have to create the classic
CREATE TABLE Person
(
LastName varchar(30),
FirstName varchar,
Address varchar,
Age int(3)
)
and then to put inside all recorsd of my old table ...
Is there a more simple way to do this? for example COPY Person IN Person_2005.
Yes ... if can you explain me better how i can to do take a schema table and create another table?
thank you very much ....
Franco Lucci
Greenhorn

Joined: May 07, 2005
Posts: 6
Thanks ... I resolved it with
"SELECT * INTO Customers_2005 FROM Customers"

thank you very much for your interest.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Franco,
Thanks for posting the final query.
 
Consider Paul's rocket mass heater.
 
subject: Save a table with another name?