• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Create table using JDBC

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 42151
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic