aspose file tools
The moose likes JDBC and the fly likes get fields and types for tables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "get fields and types for tables" Watch "get fields and types for tables" New topic
Author

get fields and types for tables

syd kahn
Greenhorn

Joined: Aug 23, 2005
Posts: 12
My goal is to write a utility like i use in my ASP database work.

given a table name in a database it auto generates a class wrapper for the table that knows how to insert/update/delete from the table.

before i go and re-invent the wheel, is there one out there that i can customize to my needs.

If not, is there some resource that outlines what classes i need to use to get at the tables rows and types? With that i can generate the set / get / select statements...

Seems simple enough... doesn't it?
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi Syd,

Most of this information can be queried through DatabaseMetaData class, which you can retrieve using a Connection class's getMetaData() method.

Other more complex, but also more powerful solutions exist. If you haven't already done so, have a look at Hibernate. Another project you may find intersting is Trails

HTH.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I did a school project that reads DDL and builds an internal model of the database. From there it inserts random data of the correct type with a variety of strategies for handling foreign keys. One could certainly take the parser and model and write something to generate data accessors for CRUD. Let me know if you'd like to see it all.

At work I use a framework that takes the model from XML (exported from Rose) and uses XSL to generate the Java. Pretty slick if you can tolerate XSL.

But, as mentioned above, this is a big job and it's already been done. I'd see if one of the available packages can do it before I wrote my own.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: get fields and types for tables
 
Similar Threads
Help with a Mapping
Database Migration (Migrating only Tables, leaving Views)
Table driven form
Merge statement for merging data of tables from two different databases
polymormsim related demos