I recently worked with Java Data Object( JDO ) on my machine to store and retrieve data from a local MySQL database. Following is the procedure how I did it. I used Eclipse IDE for writing JAVA codes.
*** Important: To build and run the project this post is useful.
First I created a property file that contains necessary information for connecting to the local MySQL and used by JDO api to create PersistenceManagerFactory class. Put the file in project's root folder.
File : datanucleus.properties
Code : http://pastebin.com/0npQb4ag
Update username , password ,db-name according to yours.
*** Important: To build and run the project this post is useful.
First I created a property file that contains necessary information for connecting to the local MySQL and used by JDO api to create PersistenceManagerFactory class. Put the file in project's root folder.
File : datanucleus.properties
Code : http://pastebin.com/0npQb4ag
Update username , password ,db-name according to yours.
Then I created a class named "UserInfo" to store username , password , email-address.
File : UserInfo.java
Code : http://pastebin.com/CAMth7db
For the annotaions' guideline visit here
Then I created a class named PMF.java to make sure that only one instance of PersistenceManagerFactory is used through out the application. That file uses datanucleus.properties
file.
File : PMF.java
Code : http://pastebin.com/24tcVgGk
Finally to test everything works I write TestJDO.java to test every thing works fine.
File : TestJDO.java
Code : http://pastebin.com/zeJgpcp9