Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can Java Persistence detect the database (Postgres,MySQL,etc.) dynamically?

843830Apr 21 2009 — edited Apr 23 2009
I need to develop a generic application which could be used for different databases, such as PostgreSQL, MySQL, Oracle, Sybase, etc. Each database has different requirements and data types which I need to map to the correct ones using @Column(columnDefinition="XXX", length=xxx) annotations.

Is there anyway to DYNAMICALLY DETECT the underlying database when the application is run? I would like my application to "know" what the database it is connecting to to generate the tables using the approprate annotations.

Also, is it possible to write conditional annotations, such as "if the database is PostgreSQL, then use these annotations... if the database is MySQL, then map this data type to XXX... etc." (This seems more like a Java 5 programming language topic, tough.) Any resources or documentation on how to do this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2009
Added on Apr 21 2009
3 comments
420 views