pentarim
pentarim

Reputation: 463

How to store data for a java applet

I have to create a java applet that needs to access static data which is around 600k in size. This data is exported from an sql database. What is the the best format for that data to be stored in (xml, json, java include file), to get fastest/easiest access to it. I am a complete java noob and this question might be stupid, but is there a way to 'compile' this data in to executable so there are no additional requests to server once the applet is loaded. Thanks in advance!

Upvotes: 0

Views: 973

Answers (2)

Aaron Digulla
Aaron Digulla

Reputation: 328556

If the data is static, just copy in the source tree next to your .java files.

From there, you can access it (from a class in the same package) with:

getClass().getClassLoader().getResourceAsStream("name");

Upvotes: 0

AlexR
AlexR

Reputation: 115328

I do not know what do you mean when you mention 'java include file'.

All the rest is OK. You can use either XML or JSON. It depends on your needs and taste. Just remember that JDK has built-in tools to parse XML and does not have such tools for JSON, so you will have to add external dependency (e.g. GSON). Generally it is not a problem but sometimes code size may be important for applets that are expected to be downloaded from server to client.

The other problems with applets is that unsigned applet cannot write to client's disk. So, whatever format you choose you have to store the information somewhere. You can store it on server, but server has access to DB anyway, so why to create copy?

So, my suggestion is the following. Store data in database. Create server side component (web service) that allows your applet to access the data. Applet should store in browser cookies user id, so next time user runs the applet it enters automatically.

To access browser cookie from applet user live connect and remember that applet tag should have MAYSCRIPT attribute.

Upvotes: 2

Related Questions