I’m working in a java project using eclipse, eclipseLink, java persistence API (JPA) and two databases (MYSQL and SQLServer) with the same structure (same tables). Sometimes I need to check the database that I’m using to apply conditional statements such as “if” or others. The question is:
How can i verify if I’m connected to a MySQL or SQLServer database using and use that information in a parameter?
I’m working in a java project using eclipse, eclipseLink, java persistence API (JPA) and
Share
I solved the problem reading the tag property and the Attribute name=”eclipselink.target-database” at the persistence.xml configuration file. I used these imports:
And this is the function that I used to read the property:
In another class you should to assign to a String the return of this method. And that’s the answer, now you can use this information in a conditional statement like “if”.