Skip to main content

How to create a DB table from legacy Java code?

4 replies [Last post]
Joined: 2009-08-14

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:
view plaincopy to clipboardprint?

1. public class DBRecord
2. {
3. public String A;
4. public int B;
5. public Date C;
6. ...
7. and so on.
8. }

public class DBRecord { public String A; public int B; public Date C; ... and so on. }

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

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-10-05

Another thought is EJBs and JSP/JSF. Try accessing the table from a JSP or a servlet, which creates the dynamic updated content. The css/xml would probably be more to your liking.

Joined: 2008-10-05


It doesn't per chance have the old JDBC/ODBC Bridge in there too, per chance?
If so, try SQL language and SQL searches, via SQL Client and the JDBC/ODBC Bridge is one way.

There's a useful book: Advanced Techniques for Java Developers, ISBN#: 0-471-18208-7 54499. If you can find it somewhere, it teaches legacy java development techniques in the old 1.1 and 1.2 era.

Static classes are used to create a table:

you use java.sql to setup the PreparedStatement or "DB2 Lookup", ResultSet, etc.

Not sure if that's what you are after, sounds like it will be in the code though. Try working on updating the SQL access to current day. The easiest thing is to remap the object to the table using updated SQL statements, it's a lot easier than rewriting the whole thing.

Joined: 2009-10-13

If you want Hibernate to construct a DB schema out of your class files by using Annotation Mapping, member variables in your class have to be marked with Hibernate Annotations like @Column, @Id, ... to be mapped to the correspondent table columns. If you want to use XML Mapping each class file needs a *.hbm.xml configuration file to be mapped.

Do activate DB schema creation set up the following properties in your hibernate.cfg.xml file:

org.hibernate.dialect.your-db-dialect update


Joined: 2009-04-15

MyEclipse comes with a tool to generate DB schemas from java POJOs (simple java classes as the one you posted).

You could also map you your classes using hibernate hbm.xml files or hibernate annotations and then make a hibernate configuration which is set to use the dialect of the database for which you want SQL scripts.