Java - no grabar datos en el recordset

   
Vista:

no grabar datos en el recordset

Publicado por felipe largacha (18 intervenciones) el 03/03/2011 18:15:42
Estoy haciendo uan aplicacion en java pa celular j2me pero no entiendo porque al ejecutar el codigo aveces se pueden guardar registros y a veces no se deja.

que esta pasando

cualquier ayuda gracias

NOTA: EN AL OTRA HOAJA ESTA EL RESTO DE CODIGO


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;

public class HighRecord extends MIDlet implements CommandListener
{

Form form, form1, form2, form3, form4;
Command c1, c2, c3, c4, c5, c6,cClearAllRecord;
RecordStore rs;
ByteArrayOutputStream bosStream;
DataOutputStream dos;
byte[] dat;
TextField t1, t2;
String[] tempString;
int[] tempInt;
public HighRecord()
{
try
{
rs = RecordStore.openRecordStore("HighRecord",true);

bosStream = new ByteArrayOutputStream();

}
catch (RecordStoreFullException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

tempInt = new int[3];
tempString = new String[3];
form = new Form("menu");
c1 = new Command("new", Command.SCREEN, 1);
c2 = new Command("edit", Command.SCREEN, 1);
c3 = new Command("mod3000mod", Command.SCREEN, 1);
c4 = new Command("borrar", Command.SCREEN, 1);
cClearAllRecord = new Command("Borrar Todos Los REGISTROS", Command.SCREEN,1);
form.addCommand(c1);
form.addCommand(c2);
form.addCommand(c3);
form.addCommand(c4);
form.addCommand(cClearAllRecord);
form.setCommandListener(this);

form1 = new Form("formulario");
t1 = new TextField("nombre", "", 30, TextField.ANY);
t2 = new TextField("password", "", 30, TextField.NUMERIC);
form1.append(t1);
form1.append(t2);
c5 = new Command("Guardar", Command.SCREEN,1);
form1.addCommand(c5);
form1.setCommandListener(this);

c6 = new Command("Salir", Command.SCREEN,1);

/*
* t1 = new TextField("hola","",30,TextField.ANY); t2 = new
* TextField("password","",30,TextField.NUMERIC); form2.addCommand(c5);
*/
form.setCommandListener(this);
// TODO Auto-generated constructor stub
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
// TODO Auto-generated method stub

}

protected void pauseApp()
{
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(form);
/*
* myFilter mf=new myFilter(); try { RecordEnumeration iter =
* rs.enumerateRecords(mf, null, true); } catch
* (RecordStoreNotOpenException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/

// RecordEnumeration iter = rs.enumerateRecords(mf, new SortDescend(),
// true);
// TODO Auto-generated method stub
}
public void commandAction(Command arg0, Displayable arg1)
{
// TODO Auto-generated method stub
if ( arg0 == c1 )
{
t1.setString("");
t2.setString("");
Display.getDisplay(this).setCurrent(form1);

}
if ( arg0 == c2 )
{
form2 = new Form("form2");

form2.addCommand(c6);
form2.setCommandListener(this);
form2.append("REGISTROS\n");
try
{
rs = RecordStore.openRecordStore("HighRecord",true);
for ( int i = 1; i < rs.getNumRecords(); i++ )
{
byte dat[] = rs.getRecord(i);
ByteArrayInputStream bis = new ByteArrayInputStream(dat);
DataInputStream dis = new DataInputStream(bis);
String name = dis.readUTF();
int score = dis.readInt();
form2.append(name + "" + score + "\n");
}
rs.closeRecordStore();
//
}
catch (Exception e)
{
}

Display.getDisplay(this).setCurrent(form2);

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:no grabar datos en el recordset

Publicado por felipe largacha (18 intervenciones) el 03/03/2011 18:16:16
if ( arg0 == c3 )
{

form3 = new Form("mod3000mod");
form3.addCommand(c6);
form3.setCommandListener(this);
form3.append("lola\n");
Display.getDisplay(this).setCurrent(form3);
try
{
rs.openRecordStore("HighRecord", true);
for ( int i = 1; i < rs.getNumRecords(); i++ )
{

dat = rs.getRecord(i);
ByteArrayInputStream bis = new ByteArrayInputStream(dat);
DataInputStream dis = new DataInputStream(bis);
String name = dis.readUTF();
int score = dis.readInt();
if ( score > 3000 )
{
form3.append(name + " " + score
+ "\n");
}

}
rs.closeRecordStore();
}
catch (InvalidRecordIDException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreNotOpenException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if ( arg0 == c4 )
{
form4 = new Form("form4");
form4.addCommand(c6);
form4.setCommandListener(this);
Display.getDisplay(this).setCurrent(form4);

for ( int i = 0; i < 2; i++)
{
tempInt[i] = 0;
}

try
{
rs.openRecordStore("HighRecord", true);
for ( int i = 1; i < rs.getNumRecords(); i++ )
{

dat = rs.getRecord(i);
ByteArrayInputStream bis = new ByteArrayInputStream(dat);
DataInputStream dis = new DataInputStream(bis);
String name = dis.readUTF();
int score = dis.readInt();
for( int m = 0; m < 3; m++ )
{
if ( score > tempInt[m] )
{
for ( int n = 0; n < 2 - m; n++ )
{
tempInt[2-n] = tempInt[1-n];
tempString[2-n] = tempString[1-n];
}
tempInt[m] = score;
tempString[m] = name;
break;
}
}

}
rs.closeRecordStore();
}
catch (InvalidRecordIDException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreNotOpenException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
for ( int j = 0; j < 3; j++ )
{
form4.append(tempString[j] + "" + tempInt[j]
+ "\n");
}

}

if ( arg0 == c5 )
{
int score = Integer.parseInt(t2.getString());
String name = t1.getString();
bosStream = new ByteArrayOutputStream();
dos = new DataOutputStream(bosStream);
try
{
rs = RecordStore.openRecordStore("HighRecord", true);
dos.writeUTF(name);
dos.writeInt(score);
dat = bosStream.toByteArray();
rs.addRecord(dat, 0, dat.length);
rs.closeRecordStore();
}
catch (RecordStoreFullException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

Display.getDisplay(this).setCurrent(form);

}
if ( arg0 == c6 )
{
Display.getDisplay(this).setCurrent(form);
}

if ( arg0 == cClearAllRecord )
{
try
{
for( int i = 1; i < rs.getNumRecords(); i++ )
{
rs.deleteRecord(i);
}

}
catch (RecordStoreNotOpenException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (InvalidRecordIDException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar