張生工作室
一切皆有可能
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
::
24 隨筆 :: 3 文章 :: 11 評論 :: 0 Trackbacks
<
2007年9月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(4)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2008年12月 (3)
2008年11月 (9)
2008年7月 (1)
2008年5月 (1)
2007年9月 (10)
文章檔案
2011年3月 (1)
2008年11月 (1)
2007年12月 (1)
相冊
個人影集
好友鏈接
我的C#博管
我的百度博客
搜索
最新評論
1.?re: j2me模擬短信
我同意
--15170987588
2.?re: 求助(邊位仁兄有pointbase數據庫的,麻煩傳一份給我,急)
評論內容較長,點擊標題查看
--ufo
3.?re: MathLab使用
看不明白
--天涯浪子
4.?re: MathLab使用[未登錄]
請問要表示以(-0.5)為底的指數要怎么表示啊
--小小
5.?re: MathLab使用
快速入門,方便大家...謝謝..
--292939760
閱讀排行榜
1.?第四章 管理信息系統規劃與開發方法(6096)
2.?MathLab使用(2206)
3.?數學建模公車表(1689)
4.?數學建模公車表二(974)
5.?數學建模地鐵信息(948)
評論排行榜
1.?MathLab使用(3)
2.?數學建模公車表(3)
3.?數學建模地鐵信息(2)
4.?數學建模公車表二(1)
5.?求助(邊位仁兄有pointbase數據庫的,麻煩傳一份給我,急)(1)
一個涉及rms查詢的簡單例子
/**/
/*
* ComplexFind.java
*
* Created on 2007年9月10日, 下午8:31
*/
import
java.io.ByteArrayInputStream;
import
java.io.ByteArrayOutputStream;
import
java.io.DataInputStream;
import
java.io.DataOutputStream;
import
javax.microedition.midlet.
*
;
import
javax.microedition.lcdui.
*
;
import
javax.microedition.rms.RecordEnumeration;
import
javax.microedition.rms.RecordFilter;
import
javax.microedition.rms.RecordStore;
import
javax.microedition.rms.RecordStoreException;
/** */
/**
*
*
@author
Administrator
*
@version
*/
public
class
ComplexFind
extends
MIDlet
implements
javax.microedition.lcdui.CommandListener
{
private
Display display;
private
Form form;
private
Alert alert;
private
Command exit;
private
Command start;
private
RecordStore recordstore
=
null
;
private
RecordEnumeration recordenumeration
=
null
;
private
Filter filter;
public
ComplexFind()
{
display
=
Display.getDisplay(
this
);
exit
=
new
Command(
"
Exit
"
,Command.SCREEN,
1
);
start
=
new
Command(
"
Start
"
,Command.SCREEN,
1
);
form
=
new
Form(
"
查詢復雜數據
"
);
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(
this
);
}
public
void
startApp()
{
display.setCurrent(form);
}
public
void
pauseApp()
{
}
public
void
destroyApp(
boolean
unconditional)
{
}
public
void
commandAction(Command command, Displayable displayable)
{
if
(command
==
exit)
{
destroyApp(
false
);
notifyDestroyed();
}
else
if
(command
==
start)
{
try
{
recordstore
=
RecordStore.openRecordStore(
"
myRecordStore
"
,
true
);
}
catch
(RecordStoreException ex)
{
alert
=
new
Alert(
"
Error
"
,ex.toString(),
null
,AlertType.WARNING);
ex.printStackTrace();
}
try
{
byte
[] outputRecord
=
null
;
String[] outputString
=
{
"
Adam
"
,
"
張生工作室
"
,
"
Mary
"
,
"
你好
"
,
"
張三
"
,
"
有鬼魂
"
}
;
int
outputInteger[]
=
{
15
,
10
,
5
,
78
,
23
,
32
}
;
ByteArrayOutputStream outputStream
=
new
ByteArrayOutputStream();
DataOutputStream outputDataStream
=
new
DataOutputStream(outputStream);
for
(
int
i
=
0
; i
<
outputString.length;i
++
)
{
outputDataStream.writeUTF(outputString[i]);
outputDataStream.writeInt(outputInteger[i]);
outputDataStream.flush();
outputRecord
=
outputStream.toByteArray();
recordstore.addRecord(outputRecord,
0
,outputRecord.length);
outputStream.reset();
}
outputStream.close();
outputDataStream.close();
}
catch
(Exception e)
{
alert
=
new
Alert(
"
Error
"
,e.toString(),
null
,AlertType.ERROR);
}
try
{
String inputString;
byte
[] byteInputData
=
new
byte
[
300
];
ByteArrayInputStream inputStream
=
new
ByteArrayInputStream(byteInputData);
DataInputStream inputDataStream
=
new
DataInputStream(inputStream);
if
(recordstore.getNumRecords()
>
0
)
{
filter
=
new
Filter(
"
三
"
);
recordenumeration
=
recordstore.enumerateRecords(filter,
null
,
false
);
while
(
this
.recordenumeration.hasNextElement())
{
recordstore.getRecord(
this
.recordenumeration.nextRecordId(),byteInputData,
0
);
inputString
=
inputDataStream.readUTF()
+
"
"
+
inputDataStream.readInt();
alert
=
new
Alert(
"
Reading
"
,inputString,
null
,AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
inputStream.close();
}
}
catch
(Exception e)
{
}
try
{
this
.recordstore.closeRecordStore();
}
catch
(Exception e)
{
}
if
(
this
.recordstore.listRecordStores()
!=
null
)
try
{
RecordStore.deleteRecordStore(
"
myRecordStore
"
);
filter.filterClose();
this
.recordenumeration.destroy();
}
catch
(Exception e)
{
}
}
}
class
Filter
implements
RecordFilter
{
private
String search
=
null
;
private
ByteArrayInputStream inputstream
=
null
;
private
DataInputStream datainputstream
=
null
;
public
Filter(String str)
{
this
.search
=
str;
}
public
boolean
matches(
byte
[] b)
{
String string
=
null
;
try
{
String stra
=
b.toString();
inputstream
=
new
ByteArrayInputStream(b);
datainputstream
=
new
DataInputStream(inputstream);
string
=
datainputstream.readUTF();
}
catch
(Exception e)
{
return
false
;
}
if
(string
!=
null
&&
string.indexOf(
this
.search)
!=-
1
)
{
return
true
;
}
else
return
false
;
}
public
void
filterClose()
{
try
{
if
(inputstream
!=
null
)
{
inputstream.close();
}
if
(datainputstream
!=
null
)
{
datainputstream.close();
}
}
catch
(Exception e)
{
}
}
}
}
張生工作室
posted on 2007-09-10 22:22
張生工作室
閱讀(422)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 張生工作室
主站蜘蛛池模板:
榆中县
|
德兴市
|
宁南县
|
都兰县
|
井研县
|
武定县
|
淮阳县
|
曲水县
|
岳池县
|
兰坪
|
尼勒克县
|
神农架林区
|
凌海市
|
霍林郭勒市
|
许昌县
|
九寨沟县
|
屏山县
|
涟源市
|
清流县
|
博爱县
|
遵化市
|
苍梧县
|
延津县
|
巴楚县
|
乌什县
|
蕲春县
|
文安县
|
从江县
|
方正县
|
大姚县
|
图们市
|
甘肃省
|
辽阳县
|
崇义县
|
游戏
|
和林格尔县
|
莱州市
|
即墨市
|
达州市
|
噶尔县
|
苍梧县
|