user1063108
user1063108

Reputation: 712

is it possible to write database code with java to work with all databases

I have a question which probably have been asked a million times, but I am at the point where I need to determine something like this. Here is the question: Is there some way to write Java code that queries, updates, inserts,deletes, calls stored procs etc using one type of code regardless of the fact which database there might be behind the scene? Such as I write code put it on a system and it automatically detects that db is MS SQL Server and works, then in another case database may be Oracle but application doesnt need any code changes and automatically detects and works and so on so forth....

If this is not possible then what is the best approach to almost get to this level of abstraction...e.g Have a config file and only make changes in that file regard which db drive will be used ?

Thanks

Upvotes: 1

Views: 108

Answers (2)

M Sach
M Sach

Reputation: 34424

Go for HQL(Hibernate query language) which is object oriented. For this you need to use hibernate. This way you dont have to depend on syntax of particular db. In case you want to switch from one db to another, it will be smooth

Upvotes: 0

David Fleeman
David Fleeman

Reputation: 2658

I have recently been a convert to using QueryDSL: http://www.querydsl.com/

Using this to construct your queries, all you need to do is provide the proper "template" when you declare your query object and it provides the mapping for that particular database platform. I have not went as far as using it to call stored procedures.

Upvotes: 1

Related Questions