I have been tasked with building an application that maintains a simple Student DB to store and process marks of students of 5 departments with 4 batches of students in each dept.

I first thought of developing a UI-dataAccess style application. But Was unable to process because of various complexities and my lack of experience in building db apps with java.

James gave the idea of Object Model in another thread. I never thought that OOP models can be used in DB apps. But when I read about it I came across the Persistence API and then the JDO API.

I searched for good resources to learn it but could find proper sources.

Please can anyone guide me in this topic? I need following help:

1. Resources for learning JDO
2. Guide me as to how to structure my application.

Thank you very much in advance!


Ref:

http://www.daniweb.com/software-development/java/threads/372634

I have come this far using JPA. But what is the difference between plain JPA and JDO? It would be nice if some of the brilliant Java gurus here can shed some light and guide me and provide some constructive suggestions.

//Entity Class
package employeeDB;

import javax.persistence.*;


@Entity
public class Employee {

	@Id String name;
	Double salary;
	
	public Employee()
	{
	
	}
	
	public Employee (String name, Double Salary)
	{
		this.name=name;
		this.salary=Salary;
	}
	
	public void setSalary(Double Salary)
	{
		this.salary=Salary;
	}
	
	public String toString()
	{
		return "Name: "+name+"\nSalary: "+salary ;
	}
	
}

//Main Class

package employeeDB;


import javax.persistence.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	private static void displayAll()
	{
		em.getTransaction().begin();
		TypedQuery <Employee> e=em.createQuery(displayAllQuery, Employee.class);
		List <Employee> employees=e.getResultList();
		if(employees.size()>0)
		{
			for(Employee temp:employees)
			{
				System.out.println(temp);
				System.out.println();
			}
			System.out.println(employees.size()+" Employee Records Printed!");
		}
		else
			System.out.println("Database is Empty!");
		em.getTransaction().commit();
	}
	
	private static void insert() throws IOException
	{
		System.out.print("Enter the number of Employees: ");
		n=input.nextInt();
		
					
		try{
			em.getTransaction().begin();
			for(int i=0;i<n;i++)
			{
				System.out.println("Enter the details of Employee "+(i+1)+": ");
				System.out.print("Name: ");
				name=bufferedReader.readLine();
				
				System.out.print("Salary: ");
				Salary=input.nextDouble();
				
				Employee emp=new Employee(name,Salary);
				em.persist(emp);
			}
			em.getTransaction().commit();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		Query count=em.createQuery(countQuery);
		System.out.println("\n"+n+" employee record(s) Created!\n");
		System.out.println("\n"+count.getSingleResult()+" employee record(s) Available in Database!\n");
	}
	
	private static void delete(String name)
	{
		em.getTransaction().begin();
		Employee e=(Employee) em.find(Employee.class, name);
		em.remove(e);	
		em.getTransaction().commit();
	}
	
	private static void modify(String name,Double Salary)
	{
		em.getTransaction().begin();
		Employee e=(Employee) em.find(Employee.class, name);
		e.setSalary(Salary);
		em.getTransaction().commit();
	}
	

	public static void main(String arg[]) throws IOException
	{

		
		
		System.out.println("Welcome to the Employee Database System!\n\n");
		
		do{	
			
			System.out.print("Menu: \n 1. View DB\n2. Insert \n3. Delete \n4. Modify\n5. Exit\nEnter Choice...");
			int ch=input.nextInt();
			
			switch(ch)
			{
			case 1:
				displayAll();
				break;
			case 2:
				insert();
				break;
			case 3:
				System.out.print("Name of Employee to be Deleted2: ");
				name=bufferedReader.readLine();
				delete(name);
				break;
			case 4:
				System.out.print("Name of Employee to be Modified: ");
				name=bufferedReader.readLine();
				System.out.print("New Salary: ");
				Salary=input.nextDouble();
				modify(name,Salary);
				break;
			case 5:
				if(em!=null) em.close();
				if(emf!=null) emf.close();
				exit=true;
				break;
				
			}
		
		}while(!exit);
		
	}
	
	static EntityManagerFactory emf=Persistence.createEntityManagerFactory("E:\\JAVA Programs\\EmployeeObjDB\\bin\\employeeDB\\db\\empDB.odb");
	static EntityManager em=emf.createEntityManager();
	static Scanner input=new Scanner(System.in);
	static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
	
	
	static int n;
	static String name;
	static Double Salary;
	static boolean exit=false;
	

	static String countQuery="Select count(emp) from Employee emp";
	static String displayAllQuery="Select emp from Employee emp";
	//static String selectByEmpName="Select emp from Employee emp where emp.name==:name";
	
}

Im not gonna turn back. Im determined to build my app using JPA/JDO.

Please guide me. Thanks

Please help me. Ill use JPA API. I have become somewhat familiar with JPA API and Query structures. Now, I want to use JTableBinding. But cant understand how to use it. Can anyone please provide a resource for learning this.......

This article has been dead for over six months. Start a new discussion instead.