Use jcfxbl API to operate databases in Android

Source: Internet
Author: User
Use jcfxbl API to operate databases in Android

 

Document Sorting: Wang Qiang

 

Http://blog.csdn.net/ex_net/article/details/7833641

Author: Zhang jianbo mailbox: 281451020@qq.com Phone: 13577062679 welcome to exchange calls!

 

 

 

I. Data interfaces involved in data operations

 

The object that sends the request.

Androidfxblclientapi fxbl = new androidfxblclientapi (URL );

Url = "server address" + data interface.

 

Objects that process the returned request

Fxblresponse response = new fxblresponse (RES );

 

Create a new table in the corresponding database (for example)

Test Data

 

 

2. operations on the android Gui

2.1 query data to textbox and other controls

(1) query interface

(2) stored procedures used for query

ALTER proc [dbo].[ACT_TEST_GET_KHXX](@KHBH nvarchar(100),@return_msg nvarchar(100)output,@return_value int output)as beginselect * from T_AD_TEST where KHBH=@KHBHset @return_msg=''set @return_value=1end

(3) hook up the UI query event

Findviewbyid (R. id. btnok ). setonclicklistener (New onclicklistener () {public void onclick (view v) {// The address used for query string url = "http: // 169.254.1.30: 8088 /"; url = URL + "getdbstore. ashx? Act = act_test_get_khxx milliseconds = 1 & formid = f0102 "// bind to the handler object in the request, Handler handler = new handler () {public void handlemessage (message) {Switch (message. what) {Case httpconnection. did_start: {break;} case httpconnection. did_succeed: {dofxblcallback (string) message. OBJ); break;} case httpconnection. did_error: {break ;}}}; // The request object androidfxblclientapi fxbl = new androidfxblclientapi (URL); // Add parameters corresponding to the stored procedure Fxbl. addparam ("khbh", txtbh. gettext (). tostring (); // bind the handler object fxbl. bindhandler (handler); // send the request fxbl. request ();} // The processing method after the connection is private void dofxblcallback (string res) {// The object fxblresponse response = new fxblresponse (RES) that processes the returned request ); // store the returned data arraylist 

2.2 query data to listview

(1) query interface

(2) stored procedures for query

create proc [dbo].[ACT_AD__KHXX](@KHBH nvarchar(100),@limit int,@start int,@totalcount int output)as beginselect @totalcount=count(*) from T_AD_TEST where KHBH like '%'+@KHBHselect * from T_AD_TEST where KHBH like '%'+@KHBHend

(3) UI event mounting

findViewById(R.id.btnJS).setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubString 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 Data Writing

(1) Data Writing Interface

(2) related data tables

(3) Data Writing and storage process

 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 begininsert T_AD_TEST(KHBH,KHMC,ZJLX,ZJH,LXDH) values(@KHBH,@KHMC,@ZJLX,@ZJH,@LXDH)set @return_msg=''set @return_value=1set @result=''end

(4) UI event mounting

Findviewbyid (R. id. btnadd ). setonclicklistener (New onclicklistener () {public void onclick (view v) {// todo auto-generated method stubstring url = "http: // 169.254.1.30: 8088/execute. ashx? Act = act_ad_htxx_add into MS = 7 & formid = f0201 "; handler = new handler () {public void handlemessage (message) {Switch (message. what) {Case httpconnection. did_start: {break;} // processing case httpconnection after successful connection. 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 (); // these two parameters are required and must be added before other parameters. 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", txtz.pdf. 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 ());}});

Conclusion 2.4

Data deletion, modification, and addition operations are similar.

 

Iii. Summary

Through the jcfxbl platform API, Android applications can easily access the databases on the jcfxbl platform (such as ms SQL, Oracle, MySQL, and so on)

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.