Wednesday, August 3, 2011

Limitations of Java Applets

Having installed IIS, I was still struggling to get my Applet to connect to the MySQL database, and I stumbled across this post. The grammar is questionable but of relevance to me is:

This keeps coming up ... applets trying to make JDBC database connections don't work in general ... Mainly because JDBC is a server side technology. Where applets may only always and forever communicate with the HTTP server ... which they originated from (same server as their code base) ... and in general the database will almost always be on a different server.

In other words, it doesn't matter how hard I work to get the Applet working at home, when I upload to my ISP it probably won't work, because their MySQL server is most likely on a different box to the web server with my code on it. I guess I could send them a question, but if I want to make my code robust, I probably need a more general solution. The post quoted above goes on to suggest solutions, but at this stage of my knowledge development they are all gibberish to me. I'll quote them because they include a nice collection of search strings for possible use in my research:

So, we need some kind of web service or custom query mechanism, e.g. XML RPC over HTTP, or JSON over HTTP ... where we have the APPLET invoke HTTP requests to a Servlet in the server ... which receives these requests (also handles authentication, authorization) and then uses a JDBC connection to the database to invoke some query, unpack the result set into the HTTP servlet response in a suitable format (e.g XML, JSON, etc, what ever was used for request and what ever the applet is expecting as a response).

[This] means you'd need a web app at least with a servlet listening on a URL that your applet is able to invoke, and have the database JDBC connection available to this servlet.

Years ago I posted a question on some Java forum about JDBC and Applets, and I was asked why I was using an Applet and not writing a web application with Java Script. I gave some bullshit answer at the time, but the honest answer would have been that I had never used Java script, and didn't know the first thing about it. I have used Java, I have used VB script, and I have used HTML, so I can't believe it would be that hard; but I guess I need to hit the text books again.

No comments: