0

I want to do a midlet application for save product with its bar code, product's name, product's description and price. Then it is going to be saved as it:

123123123-coca cola-soda-6.50 124512341-crystal coca-soda-7.00

well for this I have built this code:

public boolean  ProductoAgregar(String dato) // add product
{
    byte bytes[] = dato.getBytes();
        try {
            rs.addRecord(bytes, 0, bytes.length);
       return true;
        } catch (RecordStoreException ex) {
            ex.printStackTrace();
       return false;
        }


}

public boolean ProductoModificar(String dato, int id) // update product
{

try
{
    byte bytes[] = dato.getBytes();
    rs.setRecord(id, bytes, 0, dato.length());
return true;
}
catch(Exception ex)
{
return false;
}
}

public boolean ProductoEliminar(int id)// delete product
{

try
{
    rs.deleteRecord(id);
return true;
}
catch(Exception ex)
{
return false;
}
}

I don't have an idea for how to create the method for find a product (with a part of its name, or with its bar code) and what is going to return? maybe an array?
For example all products has write coca in its name (or in description) or
find a unique product with bar code.
(This is a class with I'll instance for use its methods)

gnat
  • 6,213
  • 108
  • 53
  • 73
angel uc
  • 1
  • 1

1 Answers1

0

you can try following code, by editing as per your usage. I am using below code for searching an item from RMS Data.

public boolean SearchRecord(String Rec, int pos )
{
    String [] data = getRecordData();

    Rec = Rec.substring(0,pos);
    for ( int i = 0 ; i < data.length ; i++ )
    {
        data[i] = data[i].substring(0, pos );
        if ( Rec.toString().trim().equals(data[i].toString().trim()) )
        {
            data = null; // System.gc();
            return true;
        }
    }

    data = null; // System.gc();
    return false;
}

By Changing the value of "pos" variable you can achieve your goal.

Lucifer
  • 29,392
  • 25
  • 90
  • 143