Two Laptop Bag
The moose likes Applets and the fly likes Applet doesn't establish JDBC connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet doesn Watch "Applet doesn New topic

Applet doesn't establish JDBC connection

Ben Weaver
Ranch Hand

Joined: May 10, 2000
Posts: 40
I am trying to set up an applet with JDBC functionality and can't get the thing to work. I've written the GUI so it can be loaded either as a JFrame or as a JApplet. As a JFrame application it works fine, establishing the JDBC connections and firing the appropriate Oracle queries. As an applet, it comes up fine on the screen, but does not connect to the database. All the files (the applet, a "DbLayer" class, and an inner event-handling class) are stored in a Resin web server on my machine. I've put all the applet files into a common jar file, and have put the path for this .jar file into my windows NT CLASSPATH.
What should I do to enable the connection between the applet
and our local database?
Many thanks in advance!

Joined: Jul 05, 2000
Posts: 5
hi ben,
if u need an applet to connect to a local database,there is one
mechanism for u.In ur applet u creat a clientsocket and thru I/O
streams u send the applet content to a middle application where
u will create a server socket and get the applet content thru
Object input stream or any other input stream and there itself
u establish the jdbc connection and connect to the database.
u can send ur data to database as well as u can retrieve the
data from database into the middleapplication and from there
thru streams u can send to the applet.
If u are not comfortable with socket programming u can use
middle application as servlet which requires java webserver.
if use servlet as middle application u need not create the sockets.directly u can retrieve the data from database into the
servlet and send that info to the applet thru outputstreams.
if u are not clear let me know it
thanks and regards

Ben Weaver
Ranch Hand

Joined: May 10, 2000
Posts: 40
Thanks very much, Anand. I'll try what you recommended.
Ben Weaver
Ranch Hand

Joined: May 10, 2000
Posts: 40
Got to thinking about this problem, Anand (and whoever else is interested!), and had two questions. One, if I used a servlet that would accept several String parameters from the applet in order to run the JDBC connection and queries, which MIME type would I choose as a parameter for resp.SetContentType()? I'm new to servlets, and I've seen only the usual 'text/html' as the parameter. Is there a 'text/String' or 'text/ascii' type?
Two, might I circumvent the IO problems entirely by linking the servlet and the applet with RMI? Couldn't I then pass the strings from applet to servlet as Strings without regard for http protocols?
Ben Weaver
Ranch Hand

Joined: May 10, 2000
Posts: 40
Correction: my proposed RMI connection would link the applet not to a servlet, but to a DatabaseLayer object implementing a Remote interface.
All the same, I am interested as much in the servlet as I am in the possible RMI solution, so any wisdom about the servlet resp.setContentType() parameter would be much appreciated.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Applet doesn't establish JDBC connection
It's not a secret anymore!