Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How applet can access database using browser ??????????

 
Deepak Yadav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ppl....
Is there nobody who can tell me the answer for this I am really and veri badly stuck in b/w ....Meriii nayiiyaa paar lagwaa do...bkds...this is my 100th query regarding the same...If in this world ani body knows this either mail me a sample file of policy or tell me the solution step by step..
Chaloo fir miltey hai...
Bhaiyoon ko Pardaaam,
Aur saarey bhaiii ki baheenon ko Mera pyaar bhara Hug.
Deepak Yadav
 
java puneri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of techniques through which you can make applet accessing (server residing)database.
Applet can access database through http protocol.
1.Use thin drivers if server has specific ports opened for outside world. (these drivers are available on net. )
2.Use servlet to do your database part, communicate with servlet to retrive data.
3.Write any server program & implement HTTPTunneling & decide your own tags to communicate to server program!
4.There is one more method, applet can access database using RMI communication too. I will not recommend this anyway.

PuneGuy !
 
Deepak Yadav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all Thanks very much for your reply.
Could you please send a sample code in which servlet is communicating with Database and sends the data back to Applet....
We are doing the same thing mentioned above, which works fine in Appletviewer but is not working in Browser....
Could you please send us sample code which defines the technique to run it in browser.....
 
java puneri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Deepak
I am sorry I can't send you any code for some reson as you understand!
I can tell you brief here !
following function should be there in SERVLET
I will call the following function from the doGet or doPost method of the servelt.
-------------------------------------------------------
public void senddata(HttpServletResponse response,String data){
ObjectOutputStream outputToApplet = null;
try{
outputToApplet = new ObjectOutputStream(response.getOutputStream());
outputToApplet.writeObject(data);
outputToApplet.flush();
outputToApplet.close();
}catch(Exception e){
System.out.println("MyServlet: senddata() "+e.toString());
}
}
----------------------------------------------------------------
Let me explain!
String data in parameter of the above method is the data to be sent to applet.
We are sending the object so it could be anything like StringBuffer,ResultSet etc.
Thats servlet part over!
_________________________________________________________________
Applet part!:-
public Vector getdatafromServlet(){
ObjectInputStream inputFromServlet = null;
try{
URL servletURL = new URL(servletLocation);
URLConnection servletConnection = servletURL.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
String resultdata = (String)inputFromServlet.readObject();
inputFromServlet.close();
}catch(ClassNotFoundException e){
}
catch(Exception e){
}
finally{
return resultdata;
}
}
----------------------------------------------------------------
In above function servletlocation is the url where servelt is located.
Just check out for returntype of inputFromServlet.readObject();
(I used Vector)

________________________________________________________________

I implemented the above communication I was through this So it has to work. Play around the code.
I found the above code Internet only so if you search a little bit more you will get the zip of the source code. Javawebserver 2.0 has this example!, Even you will find example in BEA weblogic server I Guess. I am sure about JWS2.0 Example.
BEST OF LUCK !
Further need assistance, I will help you ! But can't send any code to you.
 
java puneri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Deep
I found the link, Hope that helps you
B.O.LUCK

Link
http://www.j-nine.com/pubs/applet2servlet/index.htm

Downloadable ZIP
http://www.j-nine.com/pubs/applet2servlet/applet2servlet.zip

PuneGuy !
 
Deepak Yadav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks A lot Dear
Deepak
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic