Android环境下使用JCFXBL API接口操作数据库
一、数据操作中涉及到的数据接口
发送请求的对象
AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
其中url=”服务器地址”+数据接口。
处理返回请求的对象
FxBLResponse response = new FxBLResponse(res);
在相应数据库中新建一张表(如下图)
测试数据
二、安卓GUI界面操作
2.1 把数据查询到TextBox等控件内
(1)查询界面
(2)查询时用的存储过程
- ALTER proc [dbo].[ACT_TEST_GET_KHXX]
- (
- @KHBH nvarchar(100),
- @return_msg nvarchar(100)output,
- @return_value int output
- )
- as begin
- select * from T_AD_TEST where KHBH=@KHBH
- set @return_msg=''
- set @return_value=1
- end
- findViewById(R.id.btnOK).setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- //查询用的地址
- String url ="http://169.254.1.30:8088/";
- url=url+"GetDbStore.ashx?act=ACT_TEST_GET_KHXX¶ms=1&formId=F0102"
- //绑定到请求中的Handler对象,
- Handler handler = new Handler() {
- public void handleMessage(Message message) {
- switch (message.what) {
- case HttpConnection.DID_START: {
- break;
- }
- case HttpConnection.DID_SUCCEED: {
- doFxBLCallBack((String) message.obj);
- break;
- }
- case HttpConnection.DID_ERROR: {
- break;
- }
- }
- }
- };
- //发送请求的对象
- AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
- //添加与存储过程中对应的参数
- FxBL.AddParam("KHBH", txtBH.getText().toString());
- //绑定Handler对象
- FxBL.BindHandler(handler);
- //发送请求
- FxBL.Request();
- }
- //连接成后的处理方法
- private void doFxBLCallBack(String res) {
- //处理返回请求的对象
- FxBLResponse response = new FxBLResponse(res);
- //存放返回的数据
- ArrayList<HashMap<String,String>> list=response.GetArrayList();
- if (list != null) {
- //赋值
- txtKHXM.setText(list.get(0).get("KHMC"));
- txtZJLX.setText(list.get(0).get("ZJLX"));
- txtZJH.setText(list.get(0).get("ZJH"));
- txtLXDH.setText(list.get(0).get("LXDH"));
- }
- }
- });
(1)查询界面
(2)查询用的存储过程
- create proc [dbo].[ACT_AD__KHXX]
- (
- @KHBH nvarchar(100),
- @limit int,
- @start int,
- @totalcount int output
- )
- as begin
- select @totalcount=count(*) from T_AD_TEST where KHBH like '%'+@KHBH
- select * from T_AD_TEST where KHBH like '%'+@KHBH
- end
- findViewById(R.id.btnJS).setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String url ="http://169.254.1.30:8088/";
- url=url+"GetDbStoreByPage.ashx?act=ACT_AD__KHXX¶ms=3&formId=F0201"
- Handler handler = new Handler() {
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case HttpConnection.DID_START: {
- break;
- }
- case HttpConnection.DID_SUCCEED: {
- Log.i("DID_SUCCEED", ""
- + HttpConnection.DID_SUCCEED);
- doFxBLCallBack((String) msg.obj);
- break;
- }
- case HttpConnection.DID_ERROR: {
- Log.i("tetst", "test");
- break;
- }
- }
- super.handleMessage(msg);
- }
- };
- AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
- FxBL.AddParam("KHBH", txtBH.getText().toString());
- FxBL.AddParam("start", "0");
- FxBL.AddParam("limit", "20");
- FxBL.BindHandler(handler);
- FxBL.Request();
- }
- private void doFxBLCallBack(String res) {
- Log.i("click", "click");
- FxBLResponse response = new FxBLResponse(res);
- Log.i("GetSuccess", response.GetReturn_msg());
- ArrayList<HashMap<String,String>> arrayList=response.GetArrayList();
- SimpleAdapter adapter=new SimpleAdapter(FxBIActivity.this, arrayList,
- R.layout.listview,new String[]{"KHMC","LXDH"},
- new int[]{R.id.txt_list_KHMC,R.id.txt_list_lxdh});
- listView.setAdapter(adapter);
- // txt.setText(list.get(9).getValue());
- // txt.setText(response.GetRowString(1));
- }
- });
2.3 数据写入
(1)数据写入界面
(2)相关数据表
(3)数据写入存储过程
- alter proc ACT_AD_HTXX_ADD
- (
- @KHBH nvarchar(100),
- @KHMC nvarchar(100),
- @ZJLX nvarchar(100),
- @ZJH nvarchar(100),
- @LXDH nvarchar(100),
- @return_msg nvarchar(100) output,
- @return_value int output,
- @result nvarchar(100) output
- )
- as begin
- insert T_AD_TEST(KHBH,KHMC,ZJLX,ZJH,LXDH) values(@KHBH,@KHMC,@ZJLX,@ZJH,@LXDH)
- set @return_msg=''
- set @return_value=1
- set @result=''
- end
- findViewById(R.id.btnADD).setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String url = "http://169.254.1.30:8088/Execute.ashx?act=ACT_AD_HTXX_ADD¶ms=7&formId=F0201";
- Handler handler = new Handler() {
- public void handleMessage(Message message) {
- switch (message.what) {
- case HttpConnection.DID_START: {
- break;
- }
- // 连接成功后的处理
- case HttpConnection.DID_SUCCEED: {
- Log.i("DID_SUCCEED", ""
- + HttpConnection.DID_SUCCEED);
- doFxBLCallBack((String) message.obj);
- break;
- }
- case HttpConnection.DID_ERROR: {
- break;
- }
- }
- }
- };
- AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
- Log.i("KHBH", "" + txtBH.getText().toString());
- //这个两个参数是必须的,而且必须在其他参数前添加
- FxBL.AddParam("sys_username", "admin");
- FxBL.AddParam("sys_password", "123456");
- ==============
- FxBL.AddParam("KHBH", txtBH.getText().toString());
- FxBL.AddParam("KHMC", txtKHXM.getText().toString());
- FxBL.AddParam("ZJLX", txtZJLX.getText().toString());
- FxBL.AddParam("ZJH", txtZJH.getText().toString());
- FxBL.AddParam("LXDH", txtLXDH.getText().toString());
- FxBL.BindHandler(handler);
- FxBL.Request();
- }
- private void doFxBLCallBack(String res) {
- Log.i("click", "click");
- FxBLResponse response = new FxBLResponse(res);
- Log.i("GetSuccess", response.GetReturn_msg());
- }
- });
数据删除、修改和添加的操作类似。
三、总结
通过JCFXBL平台API,Android下的应用程序可以很方便的访问JCFXBL平台的数据库(如MS SQL、Oracle、MySQL等等)
相关推荐
lxhuang 2020-11-03
ChinaJoeEE 2020-08-16
Luckyunyun 2020-08-15
bapinggaitianli 2020-08-07
phpboy 2020-07-19
染血白衣 2020-11-16
SAMXIE 2020-11-04
一个智障 2020-11-15
学习web前端 2020-11-09
yiranpiaoluo 2020-11-04
88274956 2020-11-03
82387067 2020-11-03
huangliuyu00 2020-10-29
sichenglain 2020-10-27
Dayer 2020-10-27
小马的学习笔记 2020-10-23
liuweiITlove 2020-10-14
kjyiyi 2020-10-10
fanjunjaden 2020-10-09