张生工作室
一切皆有可能
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. 第四章 管理信息系统规划与开发方法(6088)
2. MathLab使用(2197)
3. 数学建模公车表(1677)
4. 数学建模公车表二(963)
5. 数学建模地铁信息(944)
评论排行榜
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
张生工作室
阅读(413)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
BlogJava
Copyright © 张生工作室