package org.maskat.demo.petstore;
import java.sql.*;
import java.util.*;

public class ItemController {

	public Vector findItemsController(String productId) {
	
		Vector ret = null;
		Connection con = null;
		ItemDAO dao = null;
		
		try{
			
			Class.forName("org.gjt.mm.mysql.Driver");
			String url = "jdbc:mysql://localhost:3306/jpetshop";
			con = DriverManager.getConnection(url);
			//cm = ConnectionManager.getConnectionManager();
			//con = cm.getConection();
			dao = new ItemDAO(con);
			ret = dao.findItems(productId);
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				if (con!=null){
					con.close();
				}
			}catch(Exception e){
				e.printStackTrace();
			}
		
		}
		
		return ret;
	}

	public Vector findItemController(String itemId) {
	
		Vector ret = null;
		Connection con = null;
		ItemDAO dao = null;
		
		try{
			
			Class.forName("org.gjt.mm.mysql.Driver");
			String url = "jdbc:mysql://localhost:3306/jpetshop";
			con = DriverManager.getConnection(url);
			//cm = ConnectionManager.getConnectionManager();
			//con = cm.getConection();
			dao = new ItemDAO(con);
			ret = dao.findItem(itemId);
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				if (con!=null){
					con.close();
				}
			}catch(Exception e){
				e.printStackTrace();
			}
		
		}
		
		return ret;
	}
}
	