public int IDgenerator(HttpServletRequest request, HttpServletResponse response,String Type)
 throws ServletException, java.io.IOException 
 {
     int UserID=0;
     String query;
     String tablename;

    if(Type.equals("purchase"))
     {
    	 tablename="purchase_record";
     }
     else
         tablename=Type;
     
     String IDcolumn=Type+"_ID";
     query="SELECT "+IDcolumn+" FROM "+tablename;

     /*
     * Here we initialize tools for making the database connection
     * and reading from the database
     */
     Connection conn=null;
     Statement stmt=null;
     
     response.setContentType("text/html");   
     PrintWriter out = response.getWriter();
     
     ResultSet resultSet=null;
     //ResultSetMetaData resultSetMeatData=null;


     try {
     //Here we load the database driver for Oracle database
     //Class.forName("oracle.jdbc.driver.OracleDriver");

     //For mySQL database the above code would look like this:
     Class.forName("com.mysql.jdbc.Driver");


     //Here we set the JDBC URL for the Oracle database
     //String url="jdbc:oracle:thin:@db.cc.puv.fi:1521:ora817";

     //For mySQL database the above code would look like
     //something this.
     //Notice that here we are accessing mg_db database
      String url="jdbc:mysql://mysql.cc.puv.fi:3306/e1100587_project";


     //Here we create a connection to the database
     conn=DriverManager.getConnection(url, "e1100587", "vxnB9ws3N5M7");

     //Here we create the statement object for executing SQL commands.
     stmt=conn.createStatement();

     //Here we execute the SQL query and save the results to a ResultSet object
     resultSet=stmt.executeQuery(query);

     //Here we get the metadata of the query results
     //resultSetMeatData=resultSet.getMetaData();
     
     while((resultSet.next())&&(!resultSet.last()));
     UserID=Integer.parseInt(resultSet.getObject(1).toString())+1;

     return UserID;
     
     }catch(Exception e){
         /*---------------*/
         out.println("<tr>"+ e.getMessage());
     }finally {
     try {
     //Here we close all open streams
     if(stmt !=null)
     stmt.close();

     if(conn!=null)
     conn.close();

     }catch(SQLException sqlexc){
         /*----------------*/
         out.println("EXception occurred while closing streams!");
     }

     }
 return 0;
 }