hi can someone tell me how to access a MS access db using a midlet?
can some one reply please doesn’t anyone know?
Have you searched around at all?
I have no idea about accessing databases, (in J2ME or otherwise) however, 1 google search told me that JDBC is the Java API for such tasks, and that it is built upon J2SE.
I doubt very much there is a version of it that will run on J2ME, but I could be mistaken.
MIDlets in general run on resource constrained devices.
Databases in general are used when dealing with large volumes of data.
I don’t see how the 2 could, or would need to, go together.
i dont know what exactly u wish do, but i think the only solution is call to a jsp, asp,… to receive the data from the database
the major problem is going to be the undocumented stuff on the jetengine part of MS Access as its not an acutal real db but a front end…
might I suggest MSDN…MS Access does not use JDBC and doesn’t use standard odbc either…
A M$ product using proprietry components?
you do suprise me
Ah well, im glad I was wrong - atleast it got the Thread going
The first question you need to ask yourself is if you really want the database to reside on the j2me device.
Keep in mind that relational databases tend to grow large pretty fast. And since most j2me devices have not much memory, it might not be an option. Of course this really depends on you intended target device(s) and usage scenario.
If you really need the database on the device, also keep in mind that you need to have a library that allows you to access the MDB (access database) on the device. On a j2se or j2ee system you would use JDBC for this, but that’s probably not an option for a j2me device due to the size of such libraries.
Does this help? If so, then please answer the question whether you really need the database to be physically on the j2me device.
sorry i would like to clear all doubts here i know that the ms access db cannot be on the midlet due to low memory but i can call my midlet to access a db through JSP right? i know how to access a db through JSP but what i don’t know is the midlet part how do i call my JSP page in J2ME? it’s call data.jsp ;D
The MIDlet accesses the jsp page by using the General Connection Framework (javax.microedition.io.*). More specifically, you’ll probably use the HttpConnection class.
Here’s a tutorial about that.
Once you have the connection and you have received the response, it’s up to you what to do with the data. The jsp page can produce the data in an XML format and you could use a library like kXML to parse the data. But that does have some overhead, so you might want to considering sending the data in a simpler format. For example, you could just send the data as a comma-separated string, and then it would be really easy to parse.
The point is, there are no built-in solutions. You need to either roll your own, or get some third-party libraries.
shmoove
yeah hi i know there is a xml parser …but how do i use it? know any good links?
http://developers.sun.com/techtopics/mobility/midp/articles/parsingxml/
But unless the data you receive needs to be really dynamic, I don’t think the overhead is worth it.
For simple applications I would output the data in a simple format like a comma-separated string and parse it manually.
shmoove
[quote] But unless the data you receive needs to be really dynamic, I don’t think the overhead is worth it.
[/quote]
I agree that doing XML parsing on a real phone could cause some major memory headaches. All the database stuff I’ve done to phones has been through a web app, but I tend to pass stuff back to the app in some sort of delimited format. You will not get Access to run on the phone. Even if you did get some db to run, memory is so limited that some sort of delimited format would be a better option, although still not recommended.
In many cases, I use a sort of chunked encoding with two bytes as the delimiter. ‘me’ = mission element, then some well defined data after it, then ‘mp’ for the map, then ‘en’ for end of data.
On the j2me client I lock down a two byte array so I’m doing as little dynamic memory usage as possible.
This is a code snipet that came from an app that had to connect to an existing php app. I was able to add to the php to respond differently to the j2me app.
// these are shared in the headers of the various network calls
private static final String ifModifiedKey = "IF-Modified-Since";
private static final String ifModifiedData = "20 Jan 2001 16:19:14 GMT";
private static final String userAgentKey = "User-Agent";
private static final String userAgentData = "Profile/MIDP-1.0 Configuration/CLDC-1.0";
private static final String contentLangKey = "Content-Language";
private static final String contentLangData = "en-US";
private static final String contentTypeKey = "Content-Type";
private static final String contentTypeUrlData = "application/x-www-form-urlencoded";
private static final String contentTypeFormData = "multipart/form-data; boundary=---1234";
private static final byte[] boundaryBytes = "-----1234".getBytes();
String url = "http://www.yourhost.com/yourapp/login.php";
try
{
c = (HttpConnection)Connector.open(url);
// Set the request method and headers
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty(ifModifiedKey, ifModifiedData);
c.setRequestProperty(userAgentKey,userAgentData);
c.setRequestProperty(contentLangKey, contentLangData);
c.setRequestProperty(contentTypeKey,contentTypeUrlData);
// Getting the output stream may flush the headers
os = c.openOutputStream();
os.write("namefield=".getBytes());
usernameBytes = tfLoginName.getString().getBytes();
os.write(usernameBytes);
os.write("&passfield=".getBytes());
os.write(tfLoginPass.getString().getBytes());
os.write("&login=Log+In\n".getBytes());
Reading the response method looked like this:
boolean done=false;
while (!done)
{
// read two character codes
opcode[0] = (byte) is.read();
if (opcode[0]==-1)
{
return amtread;
}
//System.out.println("op0="+((char)opcode[0]));
amtread++;
opcode[1] = (byte) is.read();
if (opcode[1]==-1)
{
//System.out.println("Error reading second opcode");
return -1;
}
amtread++;
//System.out.println("op1="+((char)opcode[1]));
// start checking opcodes
if ((opcode[0]=='m') && (opcode[1]=='e'))
{
// do something here
}
This is not meant to be pretty, it was meant to save as much dynamic memory allocation as possible. I just don’t trust the j2me garbage collectors.
Also, the back end for this is mysql, I wouldn’t use Access for a web app unless I knew it was for a limited audience or there was some serious customer requirement and I couldn’t talk them out of it.
Hopefully that helps a little.
Wood
;D
USe this liobrary www.j2ASPX.com/lib
it actually enables J2ME to interface with ASPX. It is simple and easy to use.
With about 15 lines of codes, it can actually retrice and send commands to databases controlled by ASPX.
Regards