Conexão JDBC DB2e

Caros amigos

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

import javax.microedition.midlet.*;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;

import java.lang.Exception;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;

import java.io.IOException;
import java.io.EOFException;

import java.util.Vector;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import javax.microedition.io.Connector;

import com.ibm.mobileservices.isync.midp.FastRecordStore;
import com.ibm.mobileservices.isync.midp.FastRecordEnumeration;

import javax.microedition.io.Connector;
import javax.microedition.io.InputConnection;
import javax.microedition.io.HttpConnection;

import com.ibm.mobileservices.isync.ISyncProvider;
import com.ibm.mobileservices.isync.ISyncConfigStore;
import com.ibm.mobileservices.isync.ISyncService;

import com.ibm.mobileservices.isync.ISync;
import com.ibm.mobileservices.isync.ISyncDriver;
import com.ibm.mobileservices.isync.midp.MIDPISyncProvider;
import com.ibm.mobileservices.isync.midp.TableMetaData;
import com.ibm.mobileservices.isync.ISyncException;
import com.ibm.mobileservices.isync.event.ISyncEvent;
import com.ibm.mobileservices.isync.event.ISyncListener;
import com.ibm.mobileservices.isync.ISyncSubscriptionSet;

import com.ibm.mobileservices.isync.midp.FastRecordStore;
import com.ibm.mobileservices.isync.sql.Types;

import com.ibm.mobileservices.isync.debug.Debug;


public class J2meMob extends MIDlet implements CommandListener, Runnable
{
	private boolean run_Sync = false;
	private Thread syncThread;
	byte[] data = new byte[128];
	// MIDP uses HttpConnection
	private HttpConnection httpConn;
	ByteArrayInputStream bin;
	DataInputStream din;
	

	//RMS Store name : This value corresponds to the remote table name to be syncronized
	private String storeName = "ADDRESS";
	
	// Sync Client API instance
	private ISyncProvider provider;
	private ISyncService service;
	private ISyncConfigStore config;
	private ISyncDriver isync;			

	private String packetUpSize, packetDownSize;

	private Command backButton;
	private Command exitButton;


	private Command syncButton;
	private Command showJ2MEButton;

	// The display for this MIDlet
	private Display display;		
	private Form statusForm;


	public J2meMob()
	{
		/* 
		 * Set up graphics presentation
		 */

		display 	= Display.getDisplay(this);
		backButton	= new Command("Back", Command.BACK, 2);
		syncButton	= new Command("Sync", Command.SCREEN, 1);
		showJ2MEButton	= new Command("J2meDB2EMob", Command.SCREEN, 1);
		exitButton = new Command("Exit", Command.SCREEN, 2);

	}

	/**
	 * Start up the MIDlet by creating the TextBox and associating
	 * the exit command and listener.
	 */
	public void startApp()
	{
		
		statusForm = new Form("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 (ISyncException neverthrownInMidp)
		{
			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
	*/
	
	private void checkDataSizeOpenStream(int recSize)
		throws IOException
	{
		if (recSize <= data.length)
		{
			// open streams if required 
			if (bin == null)
				openStreams(data);

			// reset to start of data
			((InputStream) din).reset();
		    return;
		}

		data = new byte[recSize + 40];	

		// open on new data byte array
		if (din != null)
			((InputStream) din).close();

		openStreams(data);
	}
	
	/*
	* This method allocates appropriate data stream to hold records
	*/
	
	private void openStreams(byte data[])
	{
		bin = new ByteArrayInputStream(data);
		din = new DataInputStream(bin);
	}
	
   
	
	/**
	 * Pause MIDLET Lifecycle App Method
	 */
	 
	 public void pauseApp() {
	}

	/**
	 * Destroy must cleanup everything not handled by the garbage collector.
	 * In this case there is nothing to cleanup.
	 */
	
	public void destroyApp(boolean unconditional)
	{
		if (isync != null)
		{
			try
			{
				isync.close();
			}
			catch (Exception e) { }
			isync = null;
		}
	}
	
	
	/*
	 * Respond to commands, including exit
	 * On the exit command, cleanup and notify that the MIDlet has been destroyed.
	 */
	public void commandAction(Command c, Displayable s)
	{
		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
	 */
	 
	 private void performSyncronization()
	{
		
			syncThread = new Thread(this);
			syncThread.start();
			return;
	}


	/*
	 * This method performs syncronization process.
	 */
	 public void run(){
		
		try
		{
			int rc = isync.sync();
		
		

			switch (rc)
			{
			  case ISync.RTN_SUCCEEDED:
				System.out.println("Synchronization succeeded "
					);
				break;

			  case ISync.RTN_CANCELED:
				System.out.println("Synchronization canceled "
				 	);      
				break;

			  default: 
				System.out.println("Synchronization failed "
				 	);        
				break;
			}  
		}
			catch (Exception e)
		{
			System.out.println("sync failed");
		}  
		
		readRecords(storeName);
		
	 }

	
	/*
	 * This method reads the records from RMS Store.
	 */
	private void readRecords(String storeName)	{
	
		FastRecordStore rms = null;
		System.out.println("readRecords "  + storeName);
		
			
		try
		{
			rms = FastRecordStore.openRecordStore(storeName, false);
			FastRecordEnumeration enum =
				rms.enumerateRecords(null, null, false);
	
			System.out.println("\t\treadRecords got enum # recs " 
					+ rms.getNumRecords());
			

					
			while (enum.hasNextElement())
			{
			
				int id = enum.nextRecordId();
				int recSize = -1;
				try
				{
					recSize = rms.getRecordSize(id);
					checkDataSizeOpenStream(recSize);
					recSize = rms.getRecord(id, data, 0);
				
				}
				catch (Exception e)
				{
				System.out.println(e.toString());
				}
				
				
				String s = null;
				byte dirty = din.readByte();
				if ((dirty & ISync.ROW_DELETED) != 0)
					continue;

			        readAdressRecords(din);
				
				
			}
			
		}
		catch (Exception e)
		{
			System.out.println("exception message:" + e.toString());
			
			
		}
		finally
		{
			try
			{
				if (rms != null)
					rms.closeRecordStore();
			}
			catch (Exception e) { 
				System.out.println(e.toString());
				}
		}
	}
	
	
	private void readAdressRecords(DataInputStream din) throws IOException
	{	
		String id = din.readUTF();
		System.out.println("adressId" + id);
		din.readBoolean();
		String fname = din.readUTF();
		System.out.println("firstName" + fname); 
		din.readBoolean();
		String lname = din.readUTF();
		System.out.println("lastName" + lname); 
		din.readBoolean();
		String streetAddress = din.readUTF();
		System.out.println("streetAddress" + streetAddress); 
		din.readBoolean();
		String phoneNumber = din.readUTF();
		System.out.println("streetAddress" + phoneNumber); 
	}
	
}

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…

Minha duvida é no acesso ao BD nativo DB2e…