How to create a database connectivity sqlserver2000 through J2ME? - java

I want some helps from the professional people who know a lot in theJ2Me. I work on a mobile application that the user will be stored and retreve the data from the database using sqlserver 2000.
I am new in this area ( J2ME ) and I don’t know a lot, so I want help.
one more,
j2me is not directly support the database connectivity for that purpose we can achive with the help of servlets. Insted of servlets can we use JSP's for databaseconnectvity.

There is no standard JDBC on J2ME.
The typical implementation of what you are trying to do is to have your J2ME client make HTTP requests to a remote server.
The body of the request is made up of your own data transfer and security protocol.
The remote server decodes the request body, creates an SQL request, runs it on SQLServer, encodes the result, sends it to the J2ME client as a reply to the initial http request.
The J2ME client is then free to decode and process the SQL request result in any way it likes.

Using servlets or JSPs is your call, you can use either. Also you need to ensure that you return only very minimal data, say maybe content of 20 to 50 rows depending upon the rows size. Dont send XML or other textual data, rather send them as a binary stream which you can create using the DataOutputStream class.

Related

Send continues data to client through websocket

I have a requirement to send the huge data through the websockets. My actual requirement is, the client communicates with my server for huge test data. My server will send the data assume the data size is 1GB. Its very hard to send this 1GB of data in a single response. So I choose the websockets. I am very new to this topic. I read about the websocets in multiple blogs and everyone gave a chat application example. But in my case client will ask once and my server needs to send the continues data. Is it possible to send the continues test data to the client with the websocets.? Can any one help me on this and if possible can you please provide an example.?
Note: I am using JAVA.
Thanks & Regards,
Amar.T
You already have the chat example. Use it. Try it on single computer. Probably you will need to create own protocol for sending/receiving data. Try to send by limited sizes blocks (for example 10 kb). So you will have 2 applications: client and server used websockets. I think that the main problem here is - What to do if connection was lost?

Send notification to the client from a web server

My setup consists of a Weblogic server that runs various REST services that accepts an HTTP request from a client(an android app), reads data from a MySql database and sends this data as a response to the client.
My requirement is that the client should be notified as soon as the database is updated. I have implemented a "polling" mechanism. The client constantly sends requests and checks for any changes made in the database. However this is not a very efficient mechanism.
Can you please suggest any efficient ways of achieving this?
Thanks in advance!
One of the way to use writing a CRON job for observation of Database change.
also, SO has already discussed this topic. refer below link,
Oracle database to send notification / Invoke a java method on reaching Time specified in a column

How can i Get back source data of data contained in a script PHP with Java

I explain, I tried to open my database .sqlite contained in my server in Java with jdbc:sqlite:mydb, but it doesn't work because my database ".sqlite" is distant so i creat a script php based on my server which gets back me all of my databases.
So my question How can i Get back source data of data contained in a script PHP with Java?
Thanks a lot!
PS : Sorry for my english (I'm french)
One way would be to create a service in PHP which offers the data, so that your Java application can consume it.
E.g. PHP can expose the data in an XML or JSON format, for instance over HTTP. Your Java application would then call the HTTP URL and receive the data in JSON/XML/whatever, and then parse it to extract the data from that format.
There are other ways as well, e.g. a service bus could broker the data between the different systems, but that requires much more setup (though in the long run, it does have value, if you keep adding data that you want to expose to more and more systems).
You can create PHP WebService server and write some functions to operate that databases data for fixing your problems. Then just use Java to connect with soap to your created WebService functions.
How to start webservice, try to read this one:
http://greatgandhi.wordpress.com/2009/11/25/create-a-php-webservice-in-5min-using-php-soap-and-wsdl-technology-nusoap/
Its the best way i know, if you need to send some data back to your remote db. Its a little more complicated, but much more correct way to operate remote data.

Listening for data via a publicly available URL

I'd greatly appreciate some help on this question. So, I have a device that is going to push some data in XML format using the http protocol. I give the device a URL and it pushes data to my program. I apologize for being vague but I am curious as to how to start?
I want to implement the server side of this equation, the device being the client!
There are many approach, here is a leak of info a bit and confused desire.
XML aren't optimized for mobile communication, use JSON, because has less overhead.
If the device want to send data to server, than I like to use HTTP POST and implement a something on server side to receive it, aka web service, or just a java servlet , or a simple php file...
If the server want to send something to device, than the server should use Push notification, but the payload isn't there ( the xml) , just a notification and the device will pull the xml from server, for eg via HTTP GET.
There are many other cases and imlementations: RMI, SOAP, ...sockets,... alot

Android: Transfer file over TCP Java Socket

I am currently trying to transfer a file from a Android device to a Java TCP Server, but I am unable to find a good example which explains the structure I would need to implement this. There are many Java Client&Server examples there which explain file transfer but I want to make sure if this will still work once one throws an Android Device in there.
My question is how do I implement this sort of structure? And if it doesn't work, would I be better sending the file over an HTTP connection to a PHP server? I see a lot of examples and documentation online for the later method so I presume it is more reliable. I would however prefer to use a Java server.
The file consists of a large set of coordinates recorded by the Android device which will then be sent to the server. I have not yet established how I will store this data yet but I was originally going to store them in a primitive text file.
Design
The first thing you need is something to allow you to run Java code on your server.
There are a number of options. Two of the most popular technologies are Glassfish and Apache Tomcat.
Crudely speaking Apache Tomcat is sufficient for simple client-server communication and Glassfish is used if you need to do more complex stuff. Both allow Servlets (which are essentially self contained server classes written in Java) to run on the server-side.
They handle communication with the client by launching a JVM (Java Virtual Machine) each time they receive a request. The Java servlet can run inside the JVM and respond do some processing if required before sending a response back to the client.Each new request is run in a new instance of a servlet. This makes dealing with multiple concurrent requests simpler (no need for more complex threading).
Networking (sending data to and from the server)
In networking situations the client can be a PC, an Android phone, or any other device capable of connecting to the internet. As far as the server is concerned, if the client can communicate using HTTP (a standard protocol which it understands) the it doesn't care what sort of device it is. This means that solutions for PC desktop client-server applications are similar to one for a phone.
You can use library such as Apache HTTP Components to make it easier to handle HTTP requests and responses between the device and the server. Of course you could write your own classes to do this using Sockets but this would be very time consuming, particularly if you have never done it before.
Storage of Data
If you have time I would recommend implementing some sort of database to store the information.
They have a number of benefits to such as data recovery mechanisms, indexing for fast searching of data, ensure data integrity, better structuring of data and so on.
If you decide to use a database I recommend MySQL. It is a free and more importantly - well documented.
Aside: JDBC can be used to communicate with the database with Java.
Sorry about the in-line hyperlinks - apparently my repuation isn't high enough to post more than two!
Source: Personal experience from implementing a similar design.

Categories