文档整理:王强
http://blog.csdn.net/ex_net/article/details/7833641
作者:张建波 邮箱: [email protected] 电话:13577062679 欢迎来电交流!
发送请求的对象
AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
其中url=”服务器地址”+数据接口。
处理返回请求的对象
FxBLResponse response = new FxBLResponse(res);
在相应数据库中新建一张表(如下图)
测试数据
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
(3)UI查询事件挂接
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")); } } });
2.2 把数据查询到ListView中
(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
(3)UI事件挂接
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
(4)UI事件挂接
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()); } });
2.4 小结
数据删除、修改和添加的操作类似。
通过JCFXBL平台API,Android下的应用程序可以很方便的访问JCFXBL平台的数据库(如MS SQL、Oracle、MySQL等等)