为什么我无法更新我的 J2ME RecordStore?

发布于 2024-07-16 22:49:02 字数 5903 浏览 8 评论 0原文

我基本上希望我的 Midlet 能够编辑记录。

我有这段代码,

信息添加如下

 protected void searchForNameToEdit()
 {
          Editrecord.deleteAll();

    try
    {

        rs = RecordStore.openRecordStore("Detail", true);
        RecordEnumeration re = rs.enumerateRecords(new NameMatcher(EditSearch.getString()), null, false);
        while (re.hasNextElement())
        {
            byte [] recordBuffer = re.nextRecord();
            String record = new String(recordBuffer);


            int endOfName = record.indexOf(";");
            int endOfDesc = record.indexOf(";" , endOfName + 1);
            int endOfTown = record.indexOf(";", endOfDesc + 1);
            int endOfPlace = record.indexOf(";", endOfTown + 1);
            int endOfSDay = record.indexOf("/", endOfPlace +1);
            int endOfSMonth = record.indexOf("/",endOfSDay + 1);
            int endOfSYear = record.indexOf(";", endOfSMonth + 1);
            int endOfEDay = record.indexOf("/", endOfSYear + 1);
            int endOfEMonth = record.indexOf("/", endOfEDay + 1);
            int endOfEYear = record.indexOf(";", endOfEMonth + 1);
            int endOfComment = record.indexOf(";", endOfEYear + 1);
            int endOfRating = record.indexOf (";", endOfComment + 1);
            int endOfReview = record.indexOf (";", endOfRating + 1);


            String Name = record.substring(0, endOfName);
            String Desc = record.substring(endOfName + 1, endOfDesc);
            String Town = record.substring(endOfDesc + 1, endOfTown);
            String Place= record.substring(endOfTown + 1, endOfPlace);
            String SDay = record.substring(endOfPlace +1, endOfSDay);
            String SMonth = record.substring(endOfSDay + 1, endOfSMonth);
            String SYear = record.substring(endOfSMonth + 1, endOfSYear);
            String EDay = record.substring(endOfSYear + 1, endOfEDay);
            String EMonth = record.substring(endOfEDay + 1, endOfEMonth);
            String EYear = record.substring(endOfEMonth + 1, endOfEYear);
            String Comment = record.substring(endOfEYear + 1, endOfComment);
            String Rating = record.substring(endOfComment + 1, endOfRating);
            String Review = record.substring(endOfRating + 1, endOfReview);


            EtxtName = new TextField("Name of Event: ", Name, 15, TextField.ANY);
            EdescEvent = new TextField("Describe the Event : ", Desc, 250, TextField.ANY);
            EtownEvent = new TextField("Name of Town : ", Town, 50, TextField.ANY);
            EplaceEvent = new TextField("Name of Place : ", Place, 25, TextField.ANY);
            EcommentEvent = new TextField("Any comments : ", Comment, 300, TextField.ANY);
            EStartDate = new TextField("Start Date : ", SDay + "/" + SMonth + "/" + SYear +";", 300, TextField.ANY);
            EEndDate =new TextField("End Date : ", EDay + "/" + EMonth + "/" + EYear +";", 300, TextField.ANY);
            EEventRating = new TextField("Event Rating : ", Rating, 10, TextField.ANY);
            EOverallReview = new TextField("Overall Review : ", Review, 300, TextField.ANY);


            Editrecord.append(EtxtName);
            Editrecord.append(EdescEvent);
            Editrecord.append(EtownEvent);
            Editrecord.append(EplaceEvent);
            Editrecord.append(EStartDate);
           // Editrecord.append("Start Date; " + SDay + "/" + SMonth + "/" + SYear);
            //Editrecord.append("End Date; " + EDay + "/" + EMonth + "/" + EYear);
            Editrecord.append(EEndDate);
            Editrecord.append(EcommentEvent);
            Editrecord.append(EEventRating);
            Editrecord.append(EOverallReview);




    }
        rs.closeRecordStore();
    }

    catch(Exception e)
    {
        mAlertConfirmDetailsSaved.setString("Couldn't read details");
        System.err.println("Error accessing database");
    }

    Display.setCurrent(Editrecord);

}

,这是执行更新的方法,

protected void PerformUpdate()
{
    int id;

    strEName = EtxtName.getString();
    strEDescEvent = EdescEvent.getString();
    strETown = EtownEvent.getString();
    strEPlace = EplaceEvent.getString();

    strStartDate = EStartDate.getString();

    strEndDate = EEndDate.getString();

    strECommentE = EcommentEvent.getString();
    strERating = EEventRating.getString();
    strEReview = EOverallReview.getString();


        String detailsToUpdate = strEName + ";" +"\n"+
                                 strEDescEvent + ";" + "\n"+
                                 strETown + ";" + "\n" +
                                 strEPlace + ";"+ "\n" +
                                 strEStartDate + ";" + "\n" +
                                 strEEndDate + ";" + "\n" +
                                 strECommentE + ";"+ "\n" +
                                 strERating + ";"+ "\n" +
                                 strEReview + ";";

    if (listOfIDs != null)
    {

        try {
            //RecordStore
                    rs = RecordStore.openRecordStore("Detail", true);
            for (Enumeration e = listOfIDs.elements() ; e.hasMoreElements() ;)
            {
                id  = ((Integer)e.nextElement()).intValue();
                byte [] detailsBuffer = detailsToUpdate.getBytes();
             rs.setRecord(id,detailsBuffer, 0, detailsBuffer.length);

            }

            rs.closeRecordStore();

            mAlertDeleteDone.setString("  Selected record updated");

            }
        catch(Exception e)
            {
            mAlertDeleteDone.setString("Couldn't update record");
            System.err.println("Error accessing database");
            }

    } 
    else
    {
        mAlertDeleteDone.setString("No records to update");
    }

    Display.setCurrent(mAlertDeleteDone, mOpeningForm);
}

我一直得到的只是没有要更新的记录的其他结果,我没有理由为什么?

请帮助或给我发送有用的教程,谢谢

I basically want my Midlet the ability to edit records.

I have this code

the information is added as follows

 protected void searchForNameToEdit()
 {
          Editrecord.deleteAll();

    try
    {

        rs = RecordStore.openRecordStore("Detail", true);
        RecordEnumeration re = rs.enumerateRecords(new NameMatcher(EditSearch.getString()), null, false);
        while (re.hasNextElement())
        {
            byte [] recordBuffer = re.nextRecord();
            String record = new String(recordBuffer);


            int endOfName = record.indexOf(";");
            int endOfDesc = record.indexOf(";" , endOfName + 1);
            int endOfTown = record.indexOf(";", endOfDesc + 1);
            int endOfPlace = record.indexOf(";", endOfTown + 1);
            int endOfSDay = record.indexOf("/", endOfPlace +1);
            int endOfSMonth = record.indexOf("/",endOfSDay + 1);
            int endOfSYear = record.indexOf(";", endOfSMonth + 1);
            int endOfEDay = record.indexOf("/", endOfSYear + 1);
            int endOfEMonth = record.indexOf("/", endOfEDay + 1);
            int endOfEYear = record.indexOf(";", endOfEMonth + 1);
            int endOfComment = record.indexOf(";", endOfEYear + 1);
            int endOfRating = record.indexOf (";", endOfComment + 1);
            int endOfReview = record.indexOf (";", endOfRating + 1);


            String Name = record.substring(0, endOfName);
            String Desc = record.substring(endOfName + 1, endOfDesc);
            String Town = record.substring(endOfDesc + 1, endOfTown);
            String Place= record.substring(endOfTown + 1, endOfPlace);
            String SDay = record.substring(endOfPlace +1, endOfSDay);
            String SMonth = record.substring(endOfSDay + 1, endOfSMonth);
            String SYear = record.substring(endOfSMonth + 1, endOfSYear);
            String EDay = record.substring(endOfSYear + 1, endOfEDay);
            String EMonth = record.substring(endOfEDay + 1, endOfEMonth);
            String EYear = record.substring(endOfEMonth + 1, endOfEYear);
            String Comment = record.substring(endOfEYear + 1, endOfComment);
            String Rating = record.substring(endOfComment + 1, endOfRating);
            String Review = record.substring(endOfRating + 1, endOfReview);


            EtxtName = new TextField("Name of Event: ", Name, 15, TextField.ANY);
            EdescEvent = new TextField("Describe the Event : ", Desc, 250, TextField.ANY);
            EtownEvent = new TextField("Name of Town : ", Town, 50, TextField.ANY);
            EplaceEvent = new TextField("Name of Place : ", Place, 25, TextField.ANY);
            EcommentEvent = new TextField("Any comments : ", Comment, 300, TextField.ANY);
            EStartDate = new TextField("Start Date : ", SDay + "/" + SMonth + "/" + SYear +";", 300, TextField.ANY);
            EEndDate =new TextField("End Date : ", EDay + "/" + EMonth + "/" + EYear +";", 300, TextField.ANY);
            EEventRating = new TextField("Event Rating : ", Rating, 10, TextField.ANY);
            EOverallReview = new TextField("Overall Review : ", Review, 300, TextField.ANY);


            Editrecord.append(EtxtName);
            Editrecord.append(EdescEvent);
            Editrecord.append(EtownEvent);
            Editrecord.append(EplaceEvent);
            Editrecord.append(EStartDate);
           // Editrecord.append("Start Date; " + SDay + "/" + SMonth + "/" + SYear);
            //Editrecord.append("End Date; " + EDay + "/" + EMonth + "/" + EYear);
            Editrecord.append(EEndDate);
            Editrecord.append(EcommentEvent);
            Editrecord.append(EEventRating);
            Editrecord.append(EOverallReview);




    }
        rs.closeRecordStore();
    }

    catch(Exception e)
    {
        mAlertConfirmDetailsSaved.setString("Couldn't read details");
        System.err.println("Error accessing database");
    }

    Display.setCurrent(Editrecord);

}

and this is the method to perform the update

protected void PerformUpdate()
{
    int id;

    strEName = EtxtName.getString();
    strEDescEvent = EdescEvent.getString();
    strETown = EtownEvent.getString();
    strEPlace = EplaceEvent.getString();

    strStartDate = EStartDate.getString();

    strEndDate = EEndDate.getString();

    strECommentE = EcommentEvent.getString();
    strERating = EEventRating.getString();
    strEReview = EOverallReview.getString();


        String detailsToUpdate = strEName + ";" +"\n"+
                                 strEDescEvent + ";" + "\n"+
                                 strETown + ";" + "\n" +
                                 strEPlace + ";"+ "\n" +
                                 strEStartDate + ";" + "\n" +
                                 strEEndDate + ";" + "\n" +
                                 strECommentE + ";"+ "\n" +
                                 strERating + ";"+ "\n" +
                                 strEReview + ";";

    if (listOfIDs != null)
    {

        try {
            //RecordStore
                    rs = RecordStore.openRecordStore("Detail", true);
            for (Enumeration e = listOfIDs.elements() ; e.hasMoreElements() ;)
            {
                id  = ((Integer)e.nextElement()).intValue();
                byte [] detailsBuffer = detailsToUpdate.getBytes();
             rs.setRecord(id,detailsBuffer, 0, detailsBuffer.length);

            }

            rs.closeRecordStore();

            mAlertDeleteDone.setString("  Selected record updated");

            }
        catch(Exception e)
            {
            mAlertDeleteDone.setString("Couldn't update record");
            System.err.println("Error accessing database");
            }

    } 
    else
    {
        mAlertDeleteDone.setString("No records to update");
    }

    Display.setCurrent(mAlertDeleteDone, mOpeningForm);
}

All I keep getting is the else outcome of No records to update and I have no reason why?

Please help or send me a helpful tutorial thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文