This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a DB table from legacy Java code?

 
John Cougar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34375
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Where is the legacy application running now? Can you export the schema (or data) from there and import it in the new place?
 
John Cougar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34375
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. Hibernate annotations can come in handy in this situation. It may well be the easiest way to go.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic