Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

query to find database..  RSS feed

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any method in java using which we can find which database we are using....let me elaborate..
I am writing a java code which will query a database.. there are two databases..SQL server and Oracle ....and I have two different SQL statement for these...I have to decide from the program which database I am using and use the appropriate SQL statement in the program...
So is there any system call to do this?
Thanks
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. What are the rules which define which database you are using? Normally this would be a configuration issue and some flag or property would direct the code which to use.
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paul
my problem is I have two statements which do the same thing.

oracle version:

select u.useraccountid,u.personid,u.useraccountnm,u.passwordtxt from PRSNACCSASSIGN p,USERACCOUNT

u,PERSONSTATUSMM ps where p.MGRACCESSLASID <> -2 and u.useraccountid > 0 and ps.EmploymentStatID = 1 And ps.UserAcctStatID =

1 And ps.ExpirationDTM >= to_date('03/03/2005', 'mm/dd/yyyy') and ps.EffectiveDTM <= to_date('03/03/2005', 'mm/dd/yyyy') and u.personid = p.personid and ps.personid = p.personid

SQL server version:

select u.useraccountid,u.personid,u.useraccountnm,u.passwordtxt from PRSNACCSASSIGN p,USERACCOUNT

u,PERSONSTATUSMM ps where p.MGRACCESSLASID <> -2 and u.useraccountid > 0 and ps.EmploymentStatID = 1 And ps.UserAcctStatID =

1 And ps.ExpirationDTM >= '03/03/2005' and ps.EffectiveDTM <= '03/03/2005' and u.personid = p.personid and ps.personid = p.personid

I want to give my program enough flexibily so that the user does not have to choose from these statements..the program should do it.

Thanks
Avi
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The two queries you've highlighted are identical in all but one respect - how you've chosen to handle the dates. If you rewrote the query to use a PreparedStatement and bind the date value as a Date object then you can use this on both DBs transparently.

If you find yourself worrying about the effect of DB specific SQL finding its way into your application then I suggest you read up on the DAO pattern.
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!