aspose file tools*
The moose likes JDBC and the fly likes How to create a DB table from legacy Java code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to create a DB table from legacy Java code?" Watch "How to create a DB table from legacy Java code?" New topic
Author

How to create a DB table from legacy Java code?

John Cougar
Greenhorn

Joined: Aug 15, 2009
Posts: 2
I was handed a legacy Java application's source code that does some DB operations. However, I did not get the DB tables/structures/SQL scripts.

I know which Java file contains the fields that map to fields in the DB. It's just a class with member variables like so:


Is there any [non-manual] way of generating a table out of the Java class that contains just these variables?

Thanks in advance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Can you parse the Java file and use the field names to create a table? It might be quicker by hand, unless you have thousands of fields, in which case your table will be unconscionably large.

And welcome to JavaRanch
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

John,
Where is the legacy application running now? Can you export the schema (or data) from there and import it in the new place?


[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
John Cougar
Greenhorn

Joined: Aug 15, 2009
Posts: 2
I was hoping I wouldn't have to parse the Java file and that there'd be a simpler, easier approach

Unfortunately I have no access to the old database or its schema. The application was "retired" several years ago, and "they're" trying to revive it now.

In the absence of any "automated" approach, I was thinking of parsing the Java file and generate a SQL script out of it.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

Hmm. Interesting problem.

I wonder if hbm2ddl would meet your needs. Even if you aren't using Hibernate, you could download the jar and add the annotations temporarily. Might be faster than writing the script yourself. Or might not - depends on how easy your file is to parse.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I agree. Hibernate annotations can come in handy in this situation. It may well be the easiest way to go.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a DB table from legacy Java code?