Thread: How to connect applet to different SQL server.
Hello, This question is not exactly on topic, but I hope someone here can point me in the correct direction. I have a postgresql database on machine1 that works fine. I have a applet served by machine2 that needs to reference the postgresql database on machine1. how do I go about doing this? My applet works fine in the JBuilder Applet viewer, but it will not run on the live systems. I think this is because of a browser security violation, but I have not been able to find a work around. Please let me know any suggestions you may have on how to make this work. Thank you for your time! Doug T.
Doug, I have used Java for a while, although I am not extremely familiar with Applets. Recently, however, I have set up a database server(using an applet and in an application) for a Java project using PostgreSQL. It seems to me that applets have a lot of trouble accessing files on other machines no matter what the situation. The way that I was able to achieve the server functionality was to use Java RMI. You would need to set up a set of objects on the machine with the database according to the standard RMI structure and then set up client classes on the machine serving the applet. Figuring it out and understanding it can be a little rough, but the end product is VERY powerful, and knowing RMI comes in handy. If you have no idea what I am talking about, you may want to go to Sun's web site and check out the RMI tutorials. There should also be books available on RMI, and I believe even some on JDBC and RMI used together. If you find a simpler way to do what you need to, jump on it. If not, however, Remote Method Invocation is a way that I know works for sure. -- Sorry if this is not too much help, Stu -- On Thu, 17 Aug 2000 doug@dupreeinc.com wrote: > Hello, > > This question is not exactly on topic, but I hope someone here can point > me in the correct direction. > > I have a postgresql database on machine1 that works fine. I have a > applet served by machine2 that needs to reference the postgresql > database on machine1. how do I go about doing this? My applet works > fine in the JBuilder Applet viewer, but it will not run on the live > systems. I think this is because of a browser security violation, but I > have not been able to find a work around. Please let me know any > suggestions you may have on how to make this work. > > Thank you for your time! > > Doug T. >
The problem with Java Applets is that most browsers disallow network connections to any machine other than the machine that the applet was downloaded from. These issues have to do with security and while there are legit reasons for wanting to connect to other machines the applet standard has never made strong requirements or specifications for telling a browser to allow such services. They are working on it.... not that it helps you know :) What Stuard Urban suggested in his email is a way of going about doing it. This would work well if you had the data access objects on a single machine and sever client servers for the applets on multiple webservers. This would allow for updates to the query java code without propogating the changes to several machines. A slightly easier solution would be to just write a java application that runs on the server and connects using jdbc to the database directly. This does not have the benifit as the above mentioned solution though. Chris Ryan doug@dupreeinc.com wrote: > > Hello, > > This question is not exactly on topic, but I hope someone here can point > me in the correct direction. > > I have a postgresql database on machine1 that works fine. I have a > applet served by machine2 that needs to reference the postgresql > database on machine1. how do I go about doing this? My applet works > fine in the JBuilder Applet viewer, but it will not run on the live > systems. I think this is because of a browser security violation, but I > have not been able to find a work around. Please let me know any > suggestions you may have on how to make this work. > > Thank you for your time! > > Doug T.
On Thu, 17 Aug 2000, Stuart Urban wrote: > Doug, > I have used Java for a while, although I am not extremely familiar with > Applets. Recently, however, I have set up a database server(using an > applet and in an application) for a Java project using PostgreSQL. It > seems to me that applets have a lot of trouble accessing files on other > machines no matter what the situation. The way that I was able to achieve > the server functionality was to use Java RMI. You would need to set up a > set of objects on the machine with the database according to the standard > RMI structure and then set up client classes on the machine serving the > applet. Figuring it out and understanding it can be a little rough, but > the end product is VERY powerful, and knowing RMI comes in handy. If you > have no idea what I am talking about, you may want to go to Sun's web site > and check out the RMI tutorials. There should also be books available on > RMI, and I believe even some on JDBC and RMI used together. If you find a > simpler way to do what you need to, jump on it. If not, however, Remote > Method Invocation is a way that I know works for sure. > We went through a similar problem at work recently. Our first attempt made use of RMI. We then discovered that Internet Explorer doesn't support RMI. You can download the RMI classes from Microsoft and add them to the Microsoft JVM, but that didn't help us, as we have external clients, who are unlikely to want to do that. Our second attempt made use of sockets. This works fine unless you anticipate having clients who sit behind somebody else's corporate firewall. We found this out the hard way. Our final solution involved Applet/Servlet communication, using HTTP tunnelling. We used the Tomcat servlet engine, in concert with Apache, for testing purposes. You can get it at http://www.apache.org. Look for the Jakarta project. If you haven't installed Tomcat previously, you can look forward to a couple of days of "fun" getting it to install properly. It's a pretty good servlet engine, and it's rapidly maturing, but the documentation is somewhat weak. I installed Tomcat myself, but someone else wrote the servlet code, so I can't give you the full on the code right now. If you think this is what you need, and require more info, remind me on Monday, and I'll dig up some more details (I'm taking off for a long weekend now). -- Ed Gomolka (egomolka@gyldan.com)
Stuart, Ed, and Chris: Thank you for the information on the java - postgresql question. I will look into RMI as I am not familar with it. I will check out the other suggestions as well. I am also tracking down a fourth option for this problem. It appears that one can sign their applet with a digital signature and request additional rights to allow connections to other systems. It is true that the java VM is allowed to connect only to the system that supplied the applet. I found some information on this at the following site: http://www.outsource-labs.com/java/security/netscape/ The problem with this method (it seems to me, but I have not tried it) is that the user will have to "ALLOW" the additional rights each time they use my applet. Again, thanks for the help! Doug Chris Ryan wrote: > The problem with Java Applets is that most browsers disallow network > connections to any machine other than the machine that the applet was > downloaded from. These issues have to do with security and while there > are legit reasons for wanting to connect to other machines the applet > standard has never made strong requirements or specifications for > telling a browser to allow such services. They are working on it.... not > that it helps you know :) > > What Stuard Urban suggested in his email is a way of going about doing > it. This would work well if you had the data access objects on a single > machine and sever client servers for the applets on multiple webservers. > This would allow for updates to the query java code without propogating > the changes to several machines. > > A slightly easier solution would be to just write a java application > that runs on the server and connects using jdbc to the database > directly. This does not have the benifit as the above mentioned solution > though. > > Chris Ryan > > doug@dupreeinc.com wrote: > > > > Hello, > > > > This question is not exactly on topic, but I hope someone here can point > > me in the correct direction. > > > > I have a postgresql database on machine1 that works fine. I have a > > applet served by machine2 that needs to reference the postgresql > > database on machine1. how do I go about doing this? My applet works > > fine in the JBuilder Applet viewer, but it will not run on the live > > systems. I think this is because of a browser security violation, but I > > have not been able to find a work around. Please let me know any > > suggestions you may have on how to make this work. > > > > Thank you for your time! > > > > Doug T.