⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recordset.java

📁 里面是关于手机通讯部的开发 主要实现了帐号的登陆
💻 JAVA
字号:
package pass;

import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.*;

public class RecordSet{
  private RecordStore Rs=null;
  private RecordEnumeration recordnum;
  private String dbName;
  public RecordSet() {
  }
  public boolean open(String Name,boolean Mode) {
    boolean state=true;
    try {
      dbName=Name;
      Rs = RecordStore.openRecordStore(Name, Mode);
    }
    catch (RecordStoreException ex) {
     state=false;
    }
    try {
      recordnum = Rs.enumerateRecords(null, null, true);
    }
    catch (RecordStoreNotOpenException ex1) {
       state=false;
    }
    return state;
  }
  public boolean initialize()
  {
    boolean state=true;
    try {
      Rs.closeRecordStore();
      Rs.deleteRecordStore("userpass");
      Rs.deleteRecordStore("accounts");
    }
    catch (RecordStoreException ex) {
      state=false;
      System.out.println(ex.getMessage());
    }
    return state;
  }
public boolean delete(int id)
  {
   boolean state=true;
    try {
      Rs.deleteRecord(id);
    }
    catch (InvalidRecordIDException ex) {
      state=false;
      System.out.println(ex.getMessage());
    }
    catch (RecordStoreNotOpenException ex) {
      state=false;
      System.out.println(ex.getMessage());
    }
    catch (RecordStoreException ex) {
      state=false;
      System.out.println(ex.getMessage());
    }
    return state;
  }
  public void close() {
    try {
      Rs.closeRecordStore();
    }
    catch (RecordStoreNotOpenException ex) {
    }
    catch (RecordStoreException ex) {
    }
  }

 public String[][]  getrecord()  {
   byte[] byteinputData = new byte[200];
   String RecordRow = "";
   ByteArrayInputStream inputstream = new ByteArrayInputStream(byteinputData);
   DataInputStream datainputstream = new DataInputStream(inputstream);
   String [][] buff=new String[recordnum.numRecords()][2];
   int i=0;
   while(recordnum.hasNextElement())
   {
    try {
      buff[i][0] = String.valueOf(recordnum.nextRecordId());
    }
    catch (InvalidRecordIDException ex) {
    }
    try {
      Rs.getRecord(Integer.parseInt(buff[i][0]),byteinputData,0);
      try {
        buff[i][1] = datainputstream.readUTF().trim();
        datainputstream.reset();
      }
      catch (IOException ex2) {
      }
    }
    catch (NumberFormatException ex1) {
      System.out.println(ex1.getMessage());
    }
    catch (InvalidRecordIDException ex1) {
        System.out.println(ex1.getMessage());
    }
    catch (RecordStoreNotOpenException ex1) {
        System.out.println(ex1.getMessage());
    }
    catch (RecordStoreException ex1) {
        System.out.println(ex1.getMessage());
    }
     i++;
   }
  try {
    datainputstream.close();
   inputstream.close();
  }
  catch (IOException ex3) {
  }
   return buff;
 }
public int Recordcount() {
  try {
    return Rs.getNumRecords();
  }
  catch (RecordStoreNotOpenException ex) {
    return 0;
  }
 }
 public boolean addnew(String Name,int record,boolean Mode){
   byte [] byteinputdata=new byte[100];
   ByteArrayOutputStream onputData=new ByteArrayOutputStream();
   DataOutputStream DataOutput=new DataOutputStream(onputData);
   boolean state=true;
   byte [] Namedata;
  try {
    DataOutput.writeUTF(Name);
  }
  catch (IOException ex1) {
  }
  try {
    DataOutput.flush();
  }
  catch (IOException ex2) {
  }
   Namedata=onputData.toByteArray();
  try {
    if(Mode)
    Rs.addRecord(Namedata, 0, Namedata.length);
  else
    Rs.setRecord(record,Namedata,0,Namedata.length);
  }
  catch (RecordStoreNotOpenException ex) {
    System.out.println(ex.getMessage());
     state=false;
  }
  catch (RecordStoreException ex) {
    System.out.println(ex.getMessage());
    state=false;
  }
  try {
    DataOutput.close();
    onputData.close();
  }
  catch (IOException ex3) {
  }
  return state;
 }

 public String read(int id)
 {
   byte[] byteinputData=new byte[100];
   String RecordRow="";
   ByteArrayInputStream inputstream=new ByteArrayInputStream(byteinputData);
   DataInputStream datainputstream=new DataInputStream(inputstream);

  try {
   Rs.getRecord(id,byteinputData,0);
  try {
    RecordRow = datainputstream.readUTF();
    datainputstream.close();
    inputstream.close();
  }
  catch (IOException ex3) {
  }
  }
  catch (InvalidRecordIDException ex) {
    System.out.println(ex.getMessage());
  }
  catch (RecordStoreNotOpenException ex) {
    System.out.println(ex.getMessage());
  }
  catch (RecordStoreException ex) {
    System.out.println(ex.getMessage());
  }
  return RecordRow;
 }
 public String getsubstr(String str ,int index)
   {
     String rStr="no found";
     String indexStr="("+String.valueOf(index)+")";
     String indexlastStr="("+String.valueOf(++index)+")";
     int statID=str.indexOf(indexStr);
     int endID=str.indexOf(indexlastStr);
     if(endID>0)
     {
       if(statID==-1)
         rStr = str.substring(0, endID);
       else
       rStr=str.substring(statID,endID);
     }
     return rStr;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -