This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet doesn't establish JDBC connection

 
Ben Weaver
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
AnandGattu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Anand
 
Ben Weaver
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much, Anand. I'll try what you recommended.
 
Ben Weaver
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic