I’m using Eclipse Juno IDE and phpMyAdmin.
I have java application, for this application I created a DB in phpMyAdmin.
Now, I have an interface for the DB methods..
Lets say the interface is like that:
public interface DBInterface{
public Vector<Employees> getAllEmplyess();
public void addNewEmployee(int ID, String name,String department);
}
Now I need to implements this interface in two ways:
1) JPA
2) JDBC
Lets say that I implemented the interface in the two ways mentioned above.
How can I choose between the with the spring mechanism in the applicationContext.xml file?
How does it work?
Why do you need both JPA and JDBC implementations (JPA is based on JDBC)?
The way to distinguish between the two is to create 2 separate DAO classes (both implement your interface)
and inject an appropriate DAO bean in spring xml (application-context file) when needed.
For example the application context xml will look something like:
(
daomember of the EmployeeService class is of typeDBInterface)or alternatively you can inject the DAO in code.