Pela especificação do Celular Nokia 9500 Comunicator, vc tem como acessar o Banco de Dados DB2e no celular…mas estou tentando fazer a conexão por jdbc só que usar a classe DriverManager, só que na específicação do celular não existe essa classe.
Alguém tem algum exemplo de fazer conexão JDBC sem usar o DriverManager?
baixei este exemplo, mas não sei como que ele criou o banco, como que ele definiu as senhas e usuários do banco, se você souber, me ajude por favor
importjavax.microedition.midlet.*;importjavax.microedition.lcdui.Alert;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Displayable;importjavax.microedition.lcdui.Choice;importjavax.microedition.lcdui.ChoiceGroup;importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.CommandListener;importjavax.microedition.lcdui.Form;importjavax.microedition.lcdui.Gauge;importjavax.microedition.lcdui.Image;importjavax.microedition.lcdui.Item;importjavax.microedition.lcdui.ItemStateListener;importjavax.microedition.lcdui.TextField;importjavax.microedition.lcdui.Ticker;importjava.lang.Exception;importjava.io.InputStream;importjava.io.ByteArrayInputStream;importjava.io.DataInputStream;importjava.io.IOException;importjava.io.EOFException;importjava.util.Vector;importjavax.microedition.midlet.*;importjavax.microedition.lcdui.*;importjavax.microedition.rms.*;importjavax.microedition.io.Connector;importcom.ibm.mobileservices.isync.midp.FastRecordStore;importcom.ibm.mobileservices.isync.midp.FastRecordEnumeration;importjavax.microedition.io.Connector;importjavax.microedition.io.InputConnection;importjavax.microedition.io.HttpConnection;importcom.ibm.mobileservices.isync.ISyncProvider;importcom.ibm.mobileservices.isync.ISyncConfigStore;importcom.ibm.mobileservices.isync.ISyncService;importcom.ibm.mobileservices.isync.ISync;importcom.ibm.mobileservices.isync.ISyncDriver;importcom.ibm.mobileservices.isync.midp.MIDPISyncProvider;importcom.ibm.mobileservices.isync.midp.TableMetaData;importcom.ibm.mobileservices.isync.ISyncException;importcom.ibm.mobileservices.isync.event.ISyncEvent;importcom.ibm.mobileservices.isync.event.ISyncListener;importcom.ibm.mobileservices.isync.ISyncSubscriptionSet;importcom.ibm.mobileservices.isync.midp.FastRecordStore;importcom.ibm.mobileservices.isync.sql.Types;importcom.ibm.mobileservices.isync.debug.Debug;publicclassJ2meMobextendsMIDletimplementsCommandListener,Runnable{privatebooleanrun_Sync=false;privateThreadsyncThread;byte[]data=newbyte[128];// MIDP uses HttpConnectionprivateHttpConnectionhttpConn;ByteArrayInputStreambin;DataInputStreamdin;//RMS Store name : This value corresponds to the remote table name to be syncronizedprivateStringstoreName="ADDRESS";// Sync Client API instanceprivateISyncProviderprovider;privateISyncServiceservice;privateISyncConfigStoreconfig;privateISyncDriverisync;privateStringpacketUpSize,packetDownSize;privateCommandbackButton;privateCommandexitButton;privateCommandsyncButton;privateCommandshowJ2MEButton;// The display for this MIDletprivateDisplaydisplay;privateFormstatusForm;publicJ2meMob(){/* * Set up graphics presentation */display=Display.getDisplay(this);backButton=newCommand("Back",Command.BACK,2);syncButton=newCommand("Sync",Command.SCREEN,1);showJ2MEButton=newCommand("J2meDB2EMob",Command.SCREEN,1);exitButton=newCommand("Exit",Command.SCREEN,2);}/** * Start up the MIDlet by creating the TextBox and associating * the exit command and listener. */publicvoidstartApp(){statusForm=newForm("DB2 J2ME Adress Book Application");statusForm.addCommand(syncButton);statusForm.addCommand(exitButton);statusForm.setCommandListener(this);display.setCurrent(statusForm);try{provider=MIDPISyncProvider.getInstance();service=provider.createSyncService("localhost","8080","Naveen","Naveen");config=service.getConfigStore(null);isync=config.getSyncDriver();}catch(ISyncExceptionneverthrownInMidp){System.out.println(" something failed "+neverthrownInMidp.toString());}//Read records from ADRESS RMS Store, If syncronization is not performed//this would return no records as ADRESS RMS Store is not created.readRecords(storeName);}/* * This method allocates appropriate data stream to hold records */privatevoidcheckDataSizeOpenStream(intrecSize)throwsIOException{if(recSize<=data.length){// open streams if required if(bin==null)openStreams(data);// reset to start of data((InputStream)din).reset();return;}data=newbyte[recSize+40];// open on new data byte arrayif(din!=null)((InputStream)din).close();openStreams(data);}/* * This method allocates appropriate data stream to hold records */privatevoidopenStreams(bytedata[]){bin=newByteArrayInputStream(data);din=newDataInputStream(bin);}/** * Pause MIDLET Lifecycle App Method */publicvoidpauseApp(){}/** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */publicvoiddestroyApp(booleanunconditional){if(isync!=null){try{isync.close();}catch(Exceptione){}isync=null;}}/* * Respond to commands, including exit * On the exit command, cleanup and notify that the MIDlet has been destroyed. */publicvoidcommandAction(Commandc,Displayables){System.out.println("commandAction "+c+" s "+s);if(c==exitButton){destroyApp(false);notifyDestroyed();return;}if(c==backButton){display.setCurrent(statusForm);statusForm.setCommandListener(this);return;}if(c==syncButton){performSyncronization();return;}}/* * This method starts the synronization thread */privatevoidperformSyncronization(){syncThread=newThread(this);syncThread.start();return;}/* * This method performs syncronization process. */publicvoidrun(){try{intrc=isync.sync();switch(rc){caseISync.RTN_SUCCEEDED:System.out.println("Synchronization succeeded ");break;caseISync.RTN_CANCELED:System.out.println("Synchronization canceled ");break;default:System.out.println("Synchronization failed ");break;}}catch(Exceptione){System.out.println("sync failed");}readRecords(storeName);}/* * This method reads the records from RMS Store. */privatevoidreadRecords(StringstoreName){FastRecordStorerms=null;System.out.println("readRecords "+storeName);try{rms=FastRecordStore.openRecordStore(storeName,false);FastRecordEnumerationenum=rms.enumerateRecords(null,null,false);System.out.println("\t\treadRecords got enum # recs "+rms.getNumRecords());while(enum.hasNextElement()){intid=enum.nextRecordId();intrecSize=-1;try{recSize=rms.getRecordSize(id);checkDataSizeOpenStream(recSize);recSize=rms.getRecord(id,data,0);}catch(Exceptione){System.out.println(e.toString());}Strings=null;bytedirty=din.readByte();if((dirty&ISync.ROW_DELETED)!=0)continue;readAdressRecords(din);}}catch(Exceptione){System.out.println("exception message:"+e.toString());}finally{try{if(rms!=null)rms.closeRecordStore();}catch(Exceptione){System.out.println(e.toString());}}}privatevoidreadAdressRecords(DataInputStreamdin)throwsIOException{Stringid=din.readUTF();System.out.println("adressId"+id);din.readBoolean();Stringfname=din.readUTF();System.out.println("firstName"+fname);din.readBoolean();Stringlname=din.readUTF();System.out.println("lastName"+lname);din.readBoolean();StringstreetAddress=din.readUTF();System.out.println("streetAddress"+streetAddress);din.readBoolean();StringphoneNumber=din.readUTF();System.out.println("streetAddress"+phoneNumber);}}
F
felipepeixotoPJ
Cara nesse exemplo que vc me passou ele usou um RecordStored(FastRecordStored) normal, só que nessa especificação criaram um RS melhor um pouco mais rápido…
Isso ele ta pegando de um WebService
service = provider.createSyncService(“localhost”, “8080”,“Naveen”, “Naveen”);
O FastRecordStored é um jeito de vc guardar os dados no celular(gravados em um arquivo texto)
Procure algo sobre RMS e RecordStored…na minha opinião a parte mais dificil é a parte das Stream q pega um pouco…