PointBase 5.5 evaluate
Hi.
I have a problem with PointBase Micro with ma midlet.
I Wrote a small DB to hadle a phone numbers, and the problem is, that the DB entries are only updated when I restart the midlet. Here is the code of the midlet (based on pointbase samples):
/*
* HelloMidlet.java
*
* Created on 18 grudzień 2006, 14:35
*/
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.pointbase.me.*;
/**
*
* @author bartek1
*/
publicclass HelloMidletextends MIDletimplements CommandListener{
/** Creates a new instance of HelloMidlet */
public HelloMidlet(){
dbm =new DBManager();
dbm.Connect();
if(!dbm.dbExists()){
dbm.CreateData();
}
}
private DBManager dbm;
private Command exitCommand;
private List list1;
private Command exitCommand1;
private Command okCommand1;
private Command okCommand2;
private Form form1;
private Form form2;
private Command backCommand1;
private Command backCommand2;
private Command exitCommand2;
private TextField textField1;
private TextField textField2;
private Command okCommand3;
private TextField textField3;
private Command okCommand4;
private List list2;
private Command backCommand3;
private Alert alert1;
private Command cancelCommand1;
private Command okCommand5;
/** This method initializes UI of the application.
*/
privatevoid initialize(){
// Insert pre-init code here
getDisplay().setCurrent(get_list1());
// Insert post-init code here
}
/** Called by the system to indicate that a command has been invoked on a particular displayable.
* @param command the Command that ws invoked
* @param displayable the Displayable on which the command was invoked
*/
publicvoid commandAction(Command command, Displayable displayable){
// Insert global pre-action code here
if (displayable == list1){
if (command == list1.SELECT_COMMAND){
switch (get_list1().getSelectedIndex()){
case 0:
// Insert pre-action code here
getDisplay().setCurrent(get_form1());
// Insert post-action code here
break;
case 1:
// Insert pre-action code here
getDisplay().setCurrent(get_form2());
// Insert post-action code here
break;
case 2:
// Insert pre-action code here
getDisplay().setCurrent(get_list2());
// Insert post-action code here
break;
case 3:
// Insert pre-action code here
getDisplay().setCurrent(get_alert1(), get_list1());
// Insert post-action code here
break;
}
}elseif (command == exitCommand1){
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
}
}elseif (displayable == form2){
if (command == backCommand2){
// Insert pre-action code here
getDisplay().setCurrent(get_list1());
// Insert post-action code here
}elseif (command == okCommand4){
// Insert pre-action code here
getDisplay().setCurrent(get_list1());
// Insert post-action code here
// TODO: Usuwanie z bazy danych.
dbm.Erase(textField3.getString());
textField3.setString("");
}
}elseif (displayable == form1){
if (command == exitCommand2){
// Insert pre-action code here
getDisplay().setCurrent(get_list1());
// Insert post-action code here
}elseif (command == okCommand3){
// Insert pre-action code here
getDisplay().setCurrent(get_list1());
// Insert post-action code here
// TODO: dodaj do bazy!!
dbm.addToBase(textField1.getString(), textField2.getString());
textField1.setString("");
textField2.setString("");
}
}elseif (displayable == list2){
if (command == backCommand3){
// Insert pre-action code here
getDisplay().setCurrent(get_list1());
// Insert post-action code here
}
}elseif (displayable == alert1){
if (command == okCommand5){
// Insert pre-action code here
// Do nothing
// Insert post-action code here
//Todo: Reset bazy danych!
if(dbm.resetDB())
destroyApp(false);
}elseif (command == cancelCommand1){
// Insert pre-action code here
getDisplay().setCurrent(get_list1());
// Insert post-action code here
}
}
// Insert global post-action code here
}
/**
* This method should return an instance of the display.
*/
public Display getDisplay(){
return Display.getDisplay(this);
}
/**
* This method should exit the midlet.
*/
publicvoid exitMIDlet(){
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
/** This method returns instance for exitCommand component and should be called instead of accessing exitCommand field directly.
* @return Instance for exitCommand component
*/
public Command get_exitCommand(){
if (exitCommand ==null){
// Insert pre-init code here
exitCommand =new Command("Exit", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand;
}
/** This method returns instance for list1 component and should be called instead of accessing list1 field directly.
* @return Instance for list1 component
*/
public List get_list1(){
if (list1 ==null){
// Insert pre-init code here
list1 =new List("Menu:", Choice.IMPLICIT,new String[]{
"Dodaj",
"Usu\u0144",
"Wy\u015Bwietl",
"Reset"
},new Image[]{
null,
null,
null,
null
});
list1.addCommand(get_exitCommand1());
list1.setCommandListener(this);
list1.setSelectedFlags(newboolean[]{
false,
false,
false,
false
});
// Insert post-init code here
}
return list1;
}
/** This method returns instance for exitCommand1 component and should be called instead of accessing exitCommand1 field directly.
* @return Instance for exitCommand1 component
*/
public Command get_exitCommand1(){
if (exitCommand1 ==null){
// Insert pre-init code here
exitCommand1 =new Command("Exit", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand1;
}
/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.
* @return Instance for okCommand1 component
*/
public Command get_okCommand1(){
if (okCommand1 ==null){
// Insert pre-init code here
okCommand1 =new Command("Ok", Command.OK, 1);
// Insert post-init code here
}
return okCommand1;
}
/** This method returns instance for okCommand2 component and should be called instead of accessing okCommand2 field directly.
* @return Instance for okCommand2 component
*/
public Command get_okCommand2(){
if (okCommand2 ==null){
// Insert pre-init code here
okCommand2 =new Command("Ok", Command.OK, 1);
// Insert post-init code here
}
return okCommand2;
}
/** This method returns instance for form1 component and should be called instead of accessing form1 field directly.
* @return Instance for form1 component
*/
public Form get_form1(){
if (form1 ==null){
// Insert pre-init code here
form1 =new Form("Dodaj",new Item[]{
get_textField1(),
get_textField2()
});
form1.addCommand(get_exitCommand2());
form1.addCommand(get_okCommand3());
form1.setCommandListener(this);
// Insert post-init code here
}
return form1;
}
/** This method returns instance for form2 component and should be called instead of accessing form2 field directly.
* @return Instance for form2 component
*/
public Form get_form2(){
if (form2 ==null){
// Insert pre-init code here
form2 =new Form("Usu\u0144",new Item[]{get_textField3()});
form2.addCommand(get_backCommand2());
form2.addCommand(get_okCommand4());
form2.setCommandListener(this);
// Insert post-init code here
}
return form2;
}
/** This method returns instance for backCommand1 component and should be called instead of accessing backCommand1 field directly.
* @return Instance for backCommand1 component
*/
public Command get_backCommand1(){
if (backCommand1 ==null){
// Insert pre-init code here
backCommand1 =new Command("Back", Command.BACK, 1);
// Insert post-init code here
}
return backCommand1;
}
/** This method returns instance for backCommand2 component and should be called instead of accessing backCommand2 field directly.
* @return Instance for backCommand2 component
*/
public Command get_backCommand2(){
if (backCommand2 ==null){
// Insert pre-init code here
backCommand2 =new Command("Back", Command.BACK, 1);
// Insert post-init code here
}
return backCommand2;
}
/** This method returns instance for exitCommand2 component and should be called instead of accessing exitCommand2 field directly.
* @return Instance for exitCommand2 component
*/
public Command get_exitCommand2(){
if (exitCommand2 ==null){
// Insert pre-init code here
exitCommand2 =new Command("Exit", Command.EXIT, 1);
// Insert post-init code here
}
return exitCommand2;
}
/** This method returns instance for textField1 component and should be called instead of accessing textField1 field directly.
* @return Instance for textField1 component
*/
public TextField get_textField1(){
if (textField1 ==null){
// Insert pre-init code here
textField1 =new TextField("Nazwa:", null, 120, TextField.ANY);
// Insert post-init code here
}
return textField1;
}
/** This method returns instance for textField2 component and should be called instead of accessing textField2 field directly.
* @return Instance for textField2 component
*/
public TextField get_textField2(){
if (textField2 ==null){
// Insert pre-init code here
textField2 =new TextField("Numer:", null, 120, TextField.NUMERIC);
// Insert post-init code here
}
return textField2;
}
/** This method returns instance for okCommand3 component and should be called instead of accessing okCommand3 field directly.
* @return Instance for okCommand3 component
*/
public Command get_okCommand3(){
if (okCommand3 ==null){
// Insert pre-init code here
okCommand3 =new Command("Ok", Command.OK, 1);
// Insert post-init code here
}
return okCommand3;
}
/** This method returns instance for textField3 component and should be called instead of accessing textField3 field directly.
* @return Instance for textField3 component
*/
public TextField get_textField3(){
if (textField3 ==null){
// Insert pre-init code here
textField3 =new TextField("Nazwa:", null, 120, TextField.ANY);
// Insert post-init code here
}
return textField3;
}
/** This method returns instance for okCommand4 component and should be called instead of accessing okCommand4 field directly.
* @return Instance for okCommand4 component
*/
public Command get_okCommand4(){
if (okCommand4 ==null){
// Insert pre-init code here
okCommand4 =new Command("Ok", Command.OK, 1);
// Insert post-init code here
}
return okCommand4;
}
/** This method returns instance for list2 component and should be called instead of accessing list2 field directly.
* @return Instance for list2 component
*/
public List get_list2(){
if (list2 ==null){
// Insert pre-init code here
list2 =new List(null, Choice.IMPLICIT,new String[0],new Image[0]);
list2.addCommand(get_backCommand3());
list2.setCommandListener(this);
list2.setSelectedFlags(newboolean[0]);
// Insert post-init code here
//TODO: wypelnic liste!!!!
String[] Table = dbm.getNamesList();
list2 =null;
list2 =new List("Wyswietl", Choice.IMPLICIT, Table,null);
list2.addCommand(get_backCommand3());
list2.setCommandListener(this);
}
return list2;
}
/** This method returns instance for backCommand3 component and should be called instead of accessing backCommand3 field directly.
* @return Instance for backCommand3 component
*/
public Command get_backCommand3(){
if (backCommand3 ==null){
// Insert pre-init code here
backCommand3 =new Command("Back", Command.BACK, 1);
// Insert post-init code here
}
return backCommand3;
}
/** This method returns instance for alert1 component and should be called instead of accessing alert1 field directly.
* @return Instance for alert1 component
*/
public Alert get_alert1(){
if (alert1 ==null){
// Insert pre-init code here
alert1 =new Alert(null,"Zresetowac baz\u0119 danych ?", null,null);
alert1.addCommand(get_cancelCommand1());
alert1.addCommand(get_okCommand5());
alert1.setCommandListener(this);
alert1.setTimeout(-2);
// Insert post-init code here
}
return alert1;
}
/** This method returns instance for cancelCommand1 component and should be called instead of accessing cancelCommand1 field directly.
* @return Instance for cancelCommand1 component
*/
public Command get_cancelCommand1(){
if (cancelCommand1 ==null){
// Insert pre-init code here
cancelCommand1 =new Command("Cancel", Command.CANCEL, 1);
// Insert post-init code here
}
return cancelCommand1;
}
/** This method returns instance for okCommand5 component and should be called instead of accessing okCommand5 field directly.
* @return Instance for okCommand5 component
*/
public Command get_okCommand5(){
if (okCommand5 ==null){
// Insert pre-init code here
okCommand5 =new Command("Ok", Command.OK, 1);
// Insert post-init code here
}
return okCommand5;
}
publicvoid startApp(){
initialize();
}
publicvoid pauseApp(){
}
publicvoid destroyApp(boolean unconditional){
dbm.disconnect();
notifyDestroyed();
}
}
DBManager.java:
/*
* DBManager.java
*
* Created on 18 grudzień 2006, 15:06
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package hello;
import com.pointbase.me.*;
import javax.microedition.rms.*;
import java.io.*;
/**
*
* @author bartek1
*/
publicclass DBManager{
private String DBName;
private Connection C;
private Statement st;
public DBManager(){
//Connect();
}
publicvoid Connect(){
try{
this.DBName ="Test";
this.C = DriverManager.getConnection("jdbc:pointbase:micro:"+ DBName,"PBPUBLIC","PBPUBLIC");
this.st = C.createStatement();
}catch (SQLException ex){
ex.printStackTrace();
}
}
publicvoid disconnect(){
// Close connection and exit
try{
if(st !=null){
st.close();
st =null;
}
if(C!=null){
C.close();
C =null;
}
}catch (Exception ex){
System.out.println(ex.getMessage());
}
}
publicvoid CreateData(){
String CreateTables ="Create Table Contact (identifier char(25), number char(25));";
try{
st.execute(CreateTables);
}catch (SQLException ex){
ex.printStackTrace();
}
}
public ResultSet getTables(){
try{
return C.getMetaData().getTables(null, null, null,null);
}catch(SQLException se){
System.out.println(se.getMessage());
returnnull;
}
}
publicboolean dbExists(){
try{
ResultSet l_rs = getTables();
if (l_rs ==null || l_rs.next() ==false)
returnfalse;
}catch( Exception ex ){
System.out.println( ex.getMessage());
returnfalse;
}
returntrue;
}
public String[] getNamesList(){
String[] Table =null;
try{
ResultSet rst = st.executeQuery("SELECT * from Contact;");
ResultSet temprst = st.executeQuery("Select count(*) from Contact");
temprst.next();
String temp = temprst.getString(1);
int iRow = Integer.parseInt(temp);
ResultSetMetaData rstm = rst.getMetaData();
int iColumns = rstm.getColumnCount();
String oneRow =new String();
Table =new String[iRow];
int i = 0;
while(rst.next()){
for(int j = 0; j < iColumns; j++){
oneRow +=" "+ rst.getString(j+1);
}
Table[i] = oneRow;
oneRow =new String();
i++;
}
rst.close();
temprst.close();
}catch (NumberFormatException ex){
ex.printStackTrace();
}catch (SQLException ex){
ex.printStackTrace();
}
return Table;
}
publicvoid addToBase(String Name, String Number){
try{
st.executeUpdate("INSERT INTO Contact (identifier, number) Values( '"+ Name +"', '" + Number +"');");
}catch (SQLException ex){
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
publicvoid Erase(String name){
try{
st.executeUpdate("DELETE from Contact where identifier = '" + name +"';");
}catch (SQLException ex){
ex.printStackTrace();
}
}
publicboolean resetDB(){
// Close connection
disconnect();
// Get a list of all record stores in the RMS
String list[]=RecordStore.listRecordStores();
// Iterate through list of record stores
for(int i=0;list!=null && i<list.length;i++){
// Delete record stores that match the recordStoreName (parameter)
// passed into the method
if(list[i].startsWith(DBName)){
try{
RecordStore.deleteRecordStore(list[i]);
}catch(Exception e){
e.printStackTrace();
returnfalse;
}
}
}
returntrue;
}
}
Please Help, because I've tried everything, and I don't know why this happens.
Message was edited by:
Black007>

