• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create table using JDBC

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to use JDBC data types to create tables in any database?

I realise this might cause problems for more complex data types, but we'd really like to have a mechanism to create tables without writing a script for every database we support. It seems tantalizingly close that we could use the meta data to create the table creation script.

Has anyone done this before?

Thanks for any help.

Cheers,

Steve
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35269
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
Are there a lot of database types? It seems like it would be easier to have an object (like a 2-d map) that looks up the proper database type for the given Java data type. This object could be loaded from a file to make it easier to change. It would also support complex data types just as easily.
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Wood:
Is there a way to use JDBC data types to create tables in any database?


Well, you could certainly do that (in fact, schema generating O/R mappers do something very much like that), but the real problem is that tables usually have relationships between them that need to be captured in the data definitions (primary keys and foreign key constraints for example) and JDBC can't provide that information (the O/R mappers I mentioned either examine Java object relations to generate that, or require some external metadata files).

In other words, you can get maybe halway there from the information in JDBC, but there just isn't enough there to do the whole thing correctly.
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,

I thought as much. We only really support MySQL and MS SQL, but it would be nice to not have to keep two installation scripts maintained and JDBC seemed the best place to look (as we're creating a better installer).

The 2d map idea sounds like a good idea - we might be able to do something like that quite easily for now.

Thanks for the help.

Cheers,

Steve
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic