Hi.
I'm not terribly familiar with JDBC but I'm willing to dive in.
I'm considering writing a database upgrade java application for an app that
runs on a couple of major relational db's.
I think I might be able to get away with using jdbc and metadata to do this..
but I think my basic approach might be:
- get table names
- copy tables to change to new name
- fix data and structure of new named tables
- rename exisiting tables to old name
- rename new named tables to existing names
The modifications are to the structure ( column lengths mostly) and to some
data in some primary key fields.
Any pointers, or approach suggestions are appreciated.
thanks
Jeff
Jeff Kish
Philipp Taprogge - 11 May 2007 21:28 GMT
Hi!
> Any pointers, or approach suggestions are appreciated.
The other guys around might correct me, but from my personal
experience is that things like this are seldom worth the effort to
do them generically... Too much knowledge about the actual database
structure and the intended upgrades have to be hard-coded into the
application.
If you want to do it in Java, just grab your db connection with the
familiar Class.forName() scheme and start issuing those statements.
You can get the metadata from the Connection object via getMetaData().
One caveat is that you will obviously need a JDBC driver that
supports the metadata you require, not all drivers do. And you
should be aware that most DBMS don't support transactions on DDL
statements like ALTER TABLE and the like, so you should be certain
you know what you are doing before running the beast.
Regards,
Phil
Jeff Kish - 11 May 2007 21:51 GMT
>Hi!
>
[quoted text clipped - 19 lines]
>
> Phil
thanks. can you use metadata functions to copy/rename tables and/or do
anything like disabling constraints (I think that might be a requirement for
renaming tables)?
Jeff
Jeff Kish
Philipp Taprogge - 12 May 2007 01:53 GMT
Hi!
> thanks. can you use metadata functions to copy/rename tables and/or do
> anything like disabling constraints (I think that might be a requirement for
> renaming tables)?
I don't you think you can. I am not 100% certain here, but I
strongly suspect, you'd have to roll your own DDL statements. Since
DDL is not part of the original SQL specs, they tend to vary greatly
across DBMS.
Google just spit out this tutorial that might give you a few hints:
http://members.aol.com/kgb1001001/Articles/JDBCMetadata/JDBC_Metadata.htm
HTH,
Phil
tzvika.barenholz@gmail.com - 13 May 2007 14:41 GMT
> Hi.
>
[quoted text clipped - 19 lines]
> Jeff
> Jeff Kish
I would avoid copying tables if at all possible. in stead, it's better
to adopt an approach of only making schema changes that go forward -
i.e. adding new objects, increasing column sizes (but not decreasing
them), adding only nullable columns or columns with default values
etc.
copying data may require extra space, which will slow it down, and
actually may fail you if the DBA hasn't allocated 2x disk space to the
DB.
also, you may want to make sure a current backup exists (some vendors
let you check that - but not in a standard way), or perhaps consider
adding a backup step to your own app.
hope this helps
T