?? dbapi.java
字號:
/* * dbapi.java * * Created on 2003年7月3日, 下午10:56 */package handenglish;/** * dbapi.java * * Created on 2002年10月8日, 下午10:37 */import javax.microedition.midlet.*;import javax.microedition.rms.*;import java.io.*;import java.util.*;import javax.microedition.lcdui.*;/** * * @author Administrator * @version *//*class DriverStruct{ public String certificate; public Image picture; public String name; public Date birthday; public short classes; public short point; public String punish; public short sex; public Date makedate; public Date enddate; public String address;}*/public class DbApi { public RecordStore myRecordStore; public boolean dbOpenJug; public DbApi(String dbName) { dbOpenJug=false; openDatabase(dbName); } public boolean openDatabase(String dbName) { if (dbOpenJug) { try { myRecordStore.closeRecordStore(); } catch(RecordStoreException e) { return false; } } try { myRecordStore= RecordStore.openRecordStore(dbName,true); dbOpenJug=true; } catch(RecordStoreException e) { return false; } return true; } public byte[] readRecord(int nowRecordId) { try { if (myRecordStore.getNumRecords()>=nowRecordId) { RecordEnumeration tempEnumRecord; tempEnumRecord=getAllRecord(); for(int i=1;i<nowRecordId;i++) tempEnumRecord.nextRecord(); return tempEnumRecord.nextRecord(); } else return null; } catch(Exception e) { return null; } } public int addDatabase(byte[] dbInfo) { if ((dbInfo.length>0)&&(dbOpenJug)) { try { return myRecordStore.addRecord(dbInfo,0,dbInfo.length); } catch(RecordStoreException e) { return -1; } } return -1; } public boolean closeDatabase() { if (dbOpenJug) { try { myRecordStore.closeRecordStore(); dbOpenJug = false; return true; } catch(RecordStoreException e) { } } return false; } public int getRecordNum() { int num; if(dbOpenJug) { try { num=myRecordStore.getNumRecords(); return num; } catch(Exception e) { return 0; } } else return 0; } public RecordEnumeration getAllRecord() { try { return myRecordStore.enumerateRecords(null,null,false); } catch(Exception e) { return null; } } public void recordIndex(Hashtable indexHash) { byte[] tempB; byte[] tempRecord = new byte[100]; int tLen,tId; RecordEnumeration tempEnumRecord; ByteArrayInputStream myByteStream=new ByteArrayInputStream(tempRecord); DataInputStream myIn=new DataInputStream(myByteStream); tempEnumRecord=getAllRecord(); try { while(tempEnumRecord.hasNextElement()) { tId = tempEnumRecord.nextRecordId(); tLen = myRecordStore.getRecordSize( tId ); if ( tLen > tempRecord.length ) tempRecord = new byte[tLen+40]; //tempRecord=tempEnumRecord.nextRecord(); myRecordStore.getRecord( tId,tempRecord,0 ); myByteStream.reset(); int tempI=myIn.readInt(); String tempS=myIn.readUTF(); indexHash.put(tempS,new Integer(tempI)); } } catch (Exception e) { } } public boolean deleteDatabase(String dbName) { if (dbOpenJug) { closeDatabase(); } try { RecordStore.deleteRecordStore(dbName); return true; } catch (Exception e) { return false; } } public boolean deleteRecord(int recordId) { try { myRecordStore.deleteRecord(recordId); return true; } catch(Exception e ) { return false; } } public void deleteAll(){ if ( !dbOpenJug ) return; try { int tempId; RecordEnumeration tempEnumRecord =getAllRecord(); while(tempEnumRecord.hasNextElement()) { tempId=tempEnumRecord.nextRecordId(); deleteRecord( tempId ); } } catch (Exception e) {} }/* public void setID(int recordID){ byte[] t = {0}; try { if ( getRecordNum() < 1 ) myRecordStore.setRecord( 1,t,0,t.length); }catch (Exception e) {} } */}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -