Home Discussion Discuss: J2ME Record Store Example

  • j2mevimanga August 18, 2013 at 10:09 AM

    /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Vector; import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.ChoiceGroup; 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.*; import javax.microedition.rms.InvalidRecordIDException; import javax.microedition.rms.RecordEnumeration; import javax.microedition.rms.RecordStore; import javax.microedition.rms.RecordStoreException; import javax.microedition.rms.RecordStoreNotOpenException; /** * @author Lukewarm */ public class RecStr extends MIDlet implements CommandListener { Form f, f1; Display d; TextField t1, t2, t3; Command c1, c2, c3, c4; ChoiceGroup v1; RecordStore rc; Vector vect; public RecStr() throws RecordStoreException { d = Display.getDisplay(this); f = new Form("Add Contact"); f1 = new Form("Add Form"); t1 = new TextField("First Name", null, 20, TextField.ANY); t2 = new TextField("Last Name", null, 20, TextField.ANY); f.append(t1); f.append(t2); c1 = new Command("Add", Command.BACK, 0); c2 = new Command("Back", Command.BACK, 0); c3 = new Command("Delete", Command.BACK, 0); c4 = new Command("ADD", Command.BACK, 0); f1.addCommand(c1); f1.addCommand(c3); f.addCommand(c2); f.addCommand(c4); f.setCommandListener(this); f1.setCommandListener(this); v1 = new ChoiceGroup("Contact", ChoiceGroup.EXCLUSIVE); f1.append(v1); rc = RecordStore.openRecordStore("contac", true); vect = new Vector(); // loadata(); } public void startApp() { d.setCurrent(f1); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { if (c == c1) { Display.getDisplay(this).setCurrent(f); } if (c == c2) { Display.getDisplay(this).setCurrent(f1); } if (c == c4) { String tffn = t1.getString().trim(); String tfln = t2.getString().trim(); try { String rcst = tffn + " " + tfln; byte[] rec = rcst.getBytes(); rc.addRecord(rec, 0, rec.length); t1.setString(""); t2.setString(""); Alert al = new Alert("Success", "Successfully Saved", null, AlertType.ALARM); Display.getDisplay(this).setCurrent(al); // loadata(); } catch (Exception e) { } } if (c == c3) { try { int ind = v1.getSelectedIndex(); String rerds = (String) vect.elementAt(ind); int i = Integer.parseInt(rerds); rc.deleteRecord(i); Alert al = new Alert("Success", "Successfully Deleted", null, AlertType.ALARM); Display.getDisplay(this).setCurrent(al); loadata(); } catch (RecordStoreException ex) { ex.printStackTrace(); } } } public void loadata() throws RecordStoreException { try { v1.deleteAll(); RecordEnumeration rcv = rc.enumerateRecords(null, null, false); while (rcv.hasNextElement()) { int cn = rcv.nextRecordId(); vect.addElement("" + cn); byte[] tr = rc.getRecord(cn); String rty = new String(tr); // rty = rty.substring(0,rty.indexOf(" ")); v1.append(rty, null); } } catch (InvalidRecordIDException ex) { ex.printStackTrace(); } catch (RecordStoreNotOpenException ex) { ex.printStackTrace(); } } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
J2ME

J2ME Record Store MIDlet Example
J2ME Record Store MIDlet Example       This is a simple program to record data and print... and delete the record: RecordStore r_store; r_store =  

J2ME

J2ME Record Store Example
J2ME Record Store Example     .... In J2ME a record store consists of a collection of records and that records remain...;   Output of the Record Store Example.. Source Code 

J2ME

J2ME Record Listener
J2ME Record Listener      ... interface with the RecordStore class for receiving Record Changed, Added, Deleted events from a record store. The Record Listener interface having the following 

J2ME

J2ME Record Data Base
J2ME Record Data Base       This Application is used to explain how to store data in the database...() and delete the data through deleteRecord() method. In this example all record 

JDBC

JDBC Select Record Example
JDBC Select Record Example  In this tutorial we will learn how select specific  record from table use mysql JDBC driver. This  select... all row record that user_name =User1.The code of   " 

SQL Tutorial

Mysql Last Record
Mysql Last Record       Mysql Last Record is used to the return the record using order by  from table. Understand with Example To grasp 

JDBC

JDBC Insert Record
JDBC Insert Record      ... Record. In this code we have a class JdbcInsertRecord.Inside this class.... In JDBC,Statement object perform an insert record using  batch updates 

J2ME

J2ME Audio Record
J2ME Audio Record       This example is used to record the audio sound  and play the recorded sound. In this example we are trying to capture the audio sound and encoded 

Java Beginners

sorting student record - Java Beginners
recording ? u want to store value in database or in file or opertinng run time.... Insert Record"); System.out.println("2. Delete Record"); System.out.println("3. Display Record"); System.out.println("4. Exit"); System.out.print 

Java-Tutorials

How To Store Image Into MySQL Using Java
How To Store Image Into MySQL Using Java In this section we will discuss about how to store an image into the database using Java and MySQL. This example... example which will demonstrate you about how to store image into database 

JDBC Questions

image store in database - JDBC
image store in database  Dear Deepak Sir, If I want to store image... with an example. Thanks & Regards, VijayaBabu.M CybermateInfotek Ltd.  ...-image-in-mysql.shtml regards meeya  Hi, Here is another example 

MySQL

Mysql Last Record
an example from 'Mysql Last Record'. To understand example we create a table... Mysql Last Record       Mysql Last Record is used to return the last records from table 

Java Beginners

Java Xml Data Store
comes in by phone or in person, she needs to record their name, address, contact... be followed up and/or purchased. You will need to store the data in a local binary... the implementation needs to change later on (perhaps they might decide to store the data 

Swing AWT

store
store  i want to store data in (.dat) file format using swing and perform operation on that insertion,deletion and update 

Java Beginners

store
store  hi i want store some information in my program and use them in other method. what shoud i do 

Java Beginners

store data from a variable in mysql?
store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable in order to apply some calculation on it, but now i want to store the result 

JSP-Tutorials

JSP Delete Record From Table Using MySQL
. In this example we will discuss about how to delete a record of database table...JSP Delete Record From Table Using MySQL This tutorial explains you that how to write a JSP for deleting a record from database table. In this section you 

JSP Servlet Questions

How to add a column with checkboxes for each record in my table in JSP
How to add a column with checkboxes for each record in my table in JSP  ... boxes for each record in my table in JSP? Also, I want to figure out a way that what records the user has checked! If you could give me the answer with an example 

JSP Servlet Questions

How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail form 

Mobile Applications Questions

How to capture video and then how to store it in mobile memory
to store it in mobile memory. so plz tel me ow to do it. if you give example code i...How to capture video and then how to store it in mobile memory  Hello there, I'm developing a mobile application where i'm capturing video from 

JSP Servlet Questions

how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password will be coming from jsp middle ware servlet how to do that?   Hi friend 

Java Beginners

Check Whether Record is already Exists or Not with Database Connectivity - Java Beginners
Check Whether Record is already Exists or Not with Database Connectivity  Hello Sir I want Program to Check Whether ID is Already exists... else that will Store in Database. plz Help Me Sir  Hi Friend, Try 

JSP Tutorials

Record user login and logout timing In JSP
Record user login and logout timing In JSP... application of maintain record of the user Login and Logout Time  in JSP...("MySQL Connect Example."); Connection conn =  

Java Beginners

Store values of dynamically generated textboxes into database
Store values of dynamically generated textboxes into database   I'm trying to create a form where the user gives number to generate textboxes. when for example the user enters 3 into textbox, three text boxes get generated 

Java Beginners

retrieve data from mysql database and store it in a variable ?
to store that data in int variable. how to do this ?   Here is an example...retrieve data from mysql database and store it in a variable ?  sir... sir   what do if we have to store the result of calculation into a new 

JDBC Questions

store and retrive image from database - JDBC
store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image...("Insert Image Example!"); String driverName = "com.mysql.jdbc.Driver"; String 

PHP Questions

Edit the record.
Edit the record.  sir, I have a table consist of huge data.I have displayed that data.side of them there is an edit button which will edit... to previous edited row or edit the previous record of the previously edited 

PHP Questions

delete record
delete record  how to delete record using checkbox and button in php   We are providing you the jsp code that displays the database table data into the html table. Along each table row there is a checkbox consists 

XML Questions

How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example 

XML Questions

How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example 

DMCA.com