資源描述:
《手機(jī)訪問(wèn)sql數(shù)據(jù)庫(kù)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、J2mec/s結(jié)構(gòu),訪問(wèn)數(shù)據(jù)庫(kù)第一步:配制好j2me客戶端。1、裝好JDK。2、裝好WirelessToolkit2.5.2手機(jī)模擬軟件。第二步:配制好serverlet服務(wù)器端。1、裝好Tomcat,并配制好。第三步:寫(xiě)手機(jī)端代碼NetMain.java類,手機(jī)程序的主類;importjavax.microedition.midlet.MIDlet;importjavax.microedition.lcdui.*;importjavax.microedition.midlet.MIDletStateChangeException;publicclassNetMainext
2、endsMIDletimplementsCommandListener{privateDisplaydis;sendMsgsm;privateCommandsd=newCommand("連接",Command.OK,1);//發(fā)送數(shù)據(jù)的按鈕privateCommandex=newCommand("退出",Command.EXIT,1);//publicNetMain(){dis=Display.getDisplay(this);////TODOAuto-generatedconstructorstub}protectedvoiddestroyApp(booleanarg0)
3、throwsMIDletStateChangeException{//TODOAuto-generatedmethodstub}protectedvoidpauseApp(){//TODOAuto-generatedmethodstub}protectedvoidstartApp()throwsMIDletStateChangeException{Formf=newForm("聯(lián)網(wǎng)測(cè)試");//顯示在屏幕的Form對(duì)象f.append("發(fā)送數(shù)據(jù)");f.addCommand(sd);f.addCommand(ex);f.setCommandListener(this);/
4、/設(shè)置按鈕監(jiān)聽(tīng)dis.setCurrent(f);//TODOAuto-generatedmethodstub}publicvoidcommandAction(Commandc,Displayabled){if(c==sd){sm=newsendMsg(this);//調(diào)用sendMsg類,將本類作為參數(shù)傳入dis.setCurrent(sm);//顯示sendMsg類}elseif(c==ex){try{destroyApp(false);}catch(MIDletStateChangeExceptione){//TODOAuto-generatedcatchblocke
5、.printStackTrace();}notifyDestroyed();}}publicvoidexit(){Formf=newForm("聯(lián)網(wǎng)測(cè)試");//顯示在屏幕的Form對(duì)象f.append("發(fā)送數(shù)據(jù)");f.addCommand(sd);f.addCommand(ex);f.setCommandListener(this);//設(shè)置按鈕監(jiān)聽(tīng)dis.setCurrent(f);//TODOAuto-generatedmethodstub}}發(fā)送請(qǐng)求得到數(shù)據(jù)類sendMsg.javaimportjavax.microedition.lcdui.*;importj
6、avax.microedition.io.*;importjava.io.*;publicclasssendMsgextendsFormimplementsCommandListener,Runnable{Stringurl="http://jike089.eicp.net:8000/test/returnMsg";//定義聯(lián)網(wǎng)用的URLStringreturnMsg="";//獲得返回字符串Commandexit=newCommand("返回",Command.OK,1);//退出程序的按鈕Threadt;//定義聯(lián)網(wǎng)用線程N(yùn)etMainnm;//NetMain的實(shí)例pu
7、blicsendMsg(NetMainnm)//構(gòu)造函數(shù),將NetMain的實(shí)例傳入{super("返回結(jié)果");//定義Form的標(biāo)題this.nm=nm;t=newThread(this);t.start();//啟動(dòng)線程}publicvoidrun(){try{returnMsg=sendHttpGet(url);//將url傳到sendHttpGet方法里做參數(shù),并返回服務(wù)器結(jié)果的字符串賦值給returnMsg//System.out.println(returnMsg);append(returnMsg)